Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not find a package configuration file provided by "Torch" with any of the following names: #12449

Open
lucasjinreal opened this issue Oct 8, 2018 · 37 comments
Labels
module: cpp-extensions Related to torch.utils.cpp_extension triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@lucasjinreal
Copy link

lucasjinreal commented Oct 8, 2018

C++ build documentation seems has code bugs:

Simply following the tutorial of newest libtorch doc, just got errors.

CMake Error at CMakeLists.txt:5 (find_package):
  By not providing "FindTorch.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Torch", but
  CMake did not find one.

  Could not find a package configuration file provided by "Torch" with any of
  the following names:

    TorchConfig.cmake
    torch-config.cmake

  Add the installation prefix of "Torch" to CMAKE_PREFIX_PATH or set
  "Torch_DIR" to a directory containing one of the above files.  If "Torch"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!
See also "/Volumes/xs/tmp/libtorch_learn/example-app/build/CMakeFiles/CMakeOutput.log".

It's cmake issue, I think documentation should more specific and make Torch finable.

cc @yf225 @glaringlee

@zou3519
Copy link
Contributor

zou3519 commented Oct 8, 2018

cc @goldsborough maybe?

@goldsborough
Copy link
Contributor

I'll take a look

@lucasjinreal
Copy link
Author

Any suggestions?

@goldsborough
Copy link
Contributor

Can you post the exact steps you took when you tried this? I assume you downloaded the latest libtorch, unzipped it, pointed your cmake at the folder etc? Could you post your terminal output with these commands? I'd like to understand the steps you took to arrive at this error.

@lucasjinreal
Copy link
Author

如果你不想下载源码,你也可以下载shared library的共享链接版本,这样下载:

wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip
unzip libtorch-shared-with-deps-latest.zip

此时我们就可以开始写一个小程序了,C++的。我们这里使用源码编译,不适用动态链接库。从下载的文件来看,最上面的文件是静态链接库,并没有源代码,说明核心的东西还是没有完全的放出来。我们先看看,如果用CMake来写一个小程序。

CMake设置

我们现在看看cmake如何设置,简单的来说,只需要几行代码:

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example-app)

find_package(Torch REQUIRED)

add_executable(example-app example-app.cpp)
target_link_libraries(example-app "${TORCH_LIBRARIES}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 11)

我们再来看看文件结构,首先我们已经下载好了 libtorch 这个文件夹,保持它不要动,另外新建一个 example-app 文件夹,并且在里面新建几个文件:

.
├── CMakeLists.txt
├── build.sh
└── example-app.cpp

其中 cpp文件写入几行简单的c++代码:

#include <torch/torch.h>
#include <iostream>

int main() {
  at::Tensor tensor = torch::rand({2, 3});
  std::cout << tensor << std::endl;
}

最后我们写一个build.sh在编译,注意,我们直接指定 刚才的libtorch的路径即可。

mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=../../libtorch ..
make

直接运行, 好吧又是库的问题:

CMake Error at CMakeLists.txt:5 (find_package):
  By not providing "FindTorch.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Torch", but
  CMake did not find one.

  Could not find a package configuration file provided by "Torch" with any of
  the following names:

    TorchConfig.cmake
    torch-config.cmake

  Add the installation prefix of "Torch" to CMAKE_PREFIX_PATH or set
  "Torch_DIR" to a directory containing one of the above files.  If "Torch"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!
See also "/Volumes/xs/tmp/libtorch_learn/example-app/build/CMakeFiles/CMakeOutput.log".

Above is the steps in Chinese but you can see the commands and setups I did. Just new a folder and write the CMakeLists.txt, and using

mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=../../libtorch ..

To builded it and ends the error.

@goldsborough
Copy link
Contributor

goldsborough commented Oct 9, 2018

Can you try changing cmake -DCMAKE_PREFIX_PATH=../../libtorch .. to cmake -DCMAKE_PREFIX_PATH=$PWD/../../libtorch ..?

@lucasjinreal
Copy link
Author

@goldsborough I am just runing this inside build folder as suggested as docs, I can see any difference between these two. But it's works and cmake config done.

However after make, some new error got:

➜  build make
Scanning dependencies of target example-app
[ 50%] Building CXX object CMakeFiles/example-app.dir/example-app.cpp.o
[100%] Linking CXX executable example-app
ld: warning: ignoring file /Volumes/xs/tmp/libtorch_learn/libtorch/lib/libtorch.so, file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): /Volumes/xs/tmp/libtorch_learn/libtorch/lib/libtorch.so
ld: warning: ignoring file /Volumes/xs/tmp/libtorch_learn/libtorch/lib/libcaffe2.so, file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): /Volumes/xs/tmp/libtorch_learn/libtorch/lib/libcaffe2.so
ld: warning: ignoring file /Volumes/xs/tmp/libtorch_learn/libtorch/lib/libc10.so, file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): /Volumes/xs/tmp/libtorch_learn/libtorch/lib/libc10.so
Undefined symbols for architecture x86_64:
  "at::CPUTensorId()", referenced from:
      at::tensorTypeIdToBackend(at::TensorTypeId) in example-app.cpp.o
  "at::CUDATensorId()", referenced from:
      at::tensorTypeIdToBackend(at::TensorTypeId) in example-app.cpp.o
  "at::SparseCPUTensorId()", referenced from:
      at::tensorTypeIdToBackend(at::TensorTypeId) in example-app.cpp.o
  "at::UndefinedTensorId()", referenced from:
      at::tensorTypeIdToBackend(at::TensorTypeId) in example-app.cpp.o
  "at::SparseCUDATensorId()", referenced from:
      at::tensorTypeIdToBackend(at::TensorTypeId) in example-app.cpp.o
  "at::UndefinedTensorImpl::_singleton", referenced from:
      at::UndefinedTensorImpl::singleton() in example-app.cpp.o
  "at::getDefaultTensorOptions()", referenced from:
      at::TensorOptions::requires_grad() const in example-app.cpp.o
      at::TensorOptions::device() const in example-app.cpp.o
  "at::globalLegacyTypeDispatch()", referenced from:
      at::TensorImpl::type() const in example-app.cpp.o
  "at::Error::Error(at::SourceLocation, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      torch::autograd::make_variable(at::Tensor, bool) in example-app.cpp.o
      torch::jit::Block::appendNode(torch::jit::Node*) in example-app.cpp.o
      torch::jit::Node::inBlockList() const in example-app.cpp.o
      torch::jit::Node::insertBefore(torch::jit::Node*) in example-app.cpp.o
      torch::jit::Node::insertAfter(torch::jit::Node*) in example-app.cpp.o
      at::DeviceGuard::set_index(int) in example-app.cpp.o
      at::tensorTypeIdToBackend(at::TensorTypeId) in example-app.cpp.o
      ...
  "at::print(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, at::Tensor const&, long long)", referenced from:
      at::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, at::Tensor const&) in example-app.cpp.o
  "at::detail::getVariableHooks()", referenced from:
      at::LegacyTypeDispatch::getTypeRaw(at::Backend, at::ScalarType, bool) in example-app.cpp.o
  "at::detail::DynamicCUDAInterface::get_device", referenced from:
      at::DeviceGuard::set_index(int) in example-app.cpp.o
  "at::detail::DynamicCUDAInterface::set_device", referenced from:
      at::DeviceGuard::set_index(int) in example-app.cpp.o
  "at::detail::DynamicCUDAInterface::unchecked_set_device", referenced from:
      at::DeviceGuard::~DeviceGuard() in example-app.cpp.o
  "at::native::rand(at::ArrayRef<long long>, at::TensorOptions const&)", referenced from:
      at::rand(at::ArrayRef<long long>, at::TensorOptions const&) in example-app.cpp.o
  "at::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, at::TensorTypeId)", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& at::detail::_str<at::TensorTypeId>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, at::TensorTypeId const&) in example-app.cpp.o
  "torch::jit::DynamicType::get()", referenced from:
      torch::jit::Value::Value(torch::jit::Node*, unsigned long) in example-app.cpp.o
  "torch::jit::tracer::getTracingState()", referenced from:
      torch::rand(at::ArrayRef<long long>, at::TensorOptions const&) in example-app.cpp.o
      torch::jit::tracer::isTracing() in example-app.cpp.o
  "torch::jit::tracer::setTracingState(std::__1::shared_ptr<torch::jit::tracer::TracingState>)", referenced from:
      torch::rand(at::ArrayRef<long long>, at::TensorOptions const&) in example-app.cpp.o
  "torch::jit::tracer::recordSourceLocation(torch::jit::Node*)", referenced from:
      torch::rand(at::ArrayRef<long long>, at::TensorOptions const&) in example-app.cpp.o
  "torch::jit::tracer::addInputs(torch::jit::Node*, char const*, at::ArrayRef<long long>)", referenced from:
      torch::rand(at::ArrayRef<long long>, at::TensorOptions const&) in example-app.cpp.o
  "torch::jit::tracer::addInputs(torch::jit::Node*, char const*, at::TensorOptions const&)", referenced from:
      torch::rand(at::ArrayRef<long long>, at::TensorOptions const&) in example-app.cpp.o
  "torch::jit::tracer::addOutput(torch::jit::Node*, at::Tensor const&)", referenced from:
      torch::rand(at::ArrayRef<long long>, at::TensorOptions const&) in example-app.cpp.o
  "torch::autograd::Variable::Impl::Impl(at::Tensor, bool, torch::autograd::Edge)", referenced from:
      c10::intrusive_ptr<torch::autograd::Variable::Impl, c10::detail::intrusive_target_default_null_type<torch::autograd::Variable::Impl> > c10::intrusive_ptr<torch::autograd::Variable::Impl, c10::detail::intrusive_target_default_null_type<torch::autograd::Variable::Impl> >::make<at::Tensor&, bool&>(at::Tensor&&&, bool&&&) in example-app.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [example-app] Error 1
make[1]: *** [CMakeFiles/example-app.dir/all] Error 2
make: *** [all] Error 2

Is that not support for macos? But I just download the macos version .so library.

@goldsborough
Copy link
Contributor

Is it possible that you're using the Linux package instead of the MacOS package? The MacOS package is https://download.pytorch.org/libtorch/nightly/cpu/libtorch-macos-latest.zip and it does not have any .so at all (which you're errors are referencing), but only .dylibs.

I'll also update the docs to emphasize that the /path/to/libtorch has to be absolute.

@lucasjinreal
Copy link
Author

@goldsborough Thank u, I will have a try.

@ganler
Copy link
Contributor

ganler commented Oct 29, 2018

@goldsborough I meet the same problem today when I try to use the cpp api in my Macos. What I've done is:

cmake_minimum_required(VERSION 3.12)
project(torch_cpp_api_test)

set(CMAKE_CXX_STANDARD 17)

find_package(Torch REQUIRED)

set(SOURCE_FILES main.cpp)

target_link_libraries(torch_cpp_api_test "${TORCH_LIBRARIES}")

add_executable(torch_cpp_api_test ${SOURCE_FILES})
  • And I got the sad message:
CMake Error at CMakeLists.txt:6 (find_package):
  By not providing "FindTorch.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Torch", but
  CMake did not find one.

  Could not find a package configuration file provided by "Torch" with any of
  the following names:

    TorchConfig.cmake
    torch-config.cmake

  Add the installation prefix of "Torch" to CMAKE_PREFIX_PATH or set
  "Torch_DIR" to a directory containing one of the above files.  If "Torch"
  provides a separate development package or SDK, be sure it has been
  installed.

I really don't know how to do as I'm not very familiar with cmake.




New:
Finally I solved this problem by adding /path/to/libtorch to PATH.

@Arnold1
Copy link

Arnold1 commented Dec 4, 2018

@ganler the libtorch-macos-latest.zip does not contain a library in ./lib, is that ok?

@primasanjaya
Copy link

same problem here, i have CUDA 9 and pytorch running on linux

i have the same error when i run this command

cmake -DCMAKE_PREFIX_PATH=~/libtorch

my libtorch folder is in the home

How to find the TorchConfig.cmake?

@goldsborough
Copy link
Contributor

@ganler you need to set CMAKE_PREFIX_PATH.
@Arnold1 which version of the library did you download? The CUDA one or Cpu one?
@primasanjaya Can you try changing ~/libtorch to $HOME/libtorch. It needs to be an absolute path. Also please share more of the commands you're using.

@Arnold1
Copy link

Arnold1 commented Dec 7, 2018

@QAlexBall
Copy link

i set "cmake -DCMAKE_PREFIX_PATH=/path/to/example-app/libtorch/ .." in cmake-options at Clion's settings.
it worked.

@goldsborough
Copy link
Contributor

@Arnold1 this is what the lib folder looks like when I download the zip folder from that link and unzip it:

➜  libtorch ls -R lib
libTHD.a                            libcaffe2_detectron_ops.dylib       libfbgemm.a                         libnnpack.a                         libonnxifi_loader.a                 libshm.dylib
libasmjit.a                         libcaffe2_module_test_dynamic.dylib libgtest.a                          libnnpack_reference_layers.a        libprotobuf-lite.a                  libtorch.1.dylib
libbenchmark.a                      libcaffe2_observers.dylib           libgtest_main.a                     libonnx.a                           libprotobuf.a                       libtorch.dylib
libbenchmark_main.a                 libcaffe2_protos.a                  libmkldnn.0.17.0.dylib              libonnx_proto.a                     libprotoc.a                         libtorch_python.dylib
libc10.dylib                        libclog.a                           libmkldnn.0.dylib                   libonnxifi.dylib                    libpthreadpool.a
libcaffe2.dylib                     libcpuinfo.a                        libmkldnn.dylib                     libonnxifi_dummy.dylib              libqnnpack.a

@codecookinging
Copy link

Thanks your guy,I met the same problem and it solved.

@ziyuang
Copy link

ziyuang commented Feb 20, 2019

What if you additionally set -DCMAKE_MODULE_PATH=path/to/libtorch/share/cmake/Torch, which keeps a TorchConfig.cmake?

@ganler
Copy link
Contributor

ganler commented Feb 22, 2019

set(Torch_DIR /usr/local/Cellar/libtorch/share/cmake/Torch)
Set the Torch_DIR to where TorchConfig.cmake is. @ziyuang

@ngimel ngimel added module: cpp-extensions Related to torch.utils.cpp_extension triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Apr 21, 2020
@glaringlee
Copy link
Contributor

@peterjc123 Can you pls advise?

@glaringlee
Copy link
Contributor

glaringlee commented Apr 23, 2020

@oranichu
CMAKE_PREFIX_PATH, try use absolute path instead of relative path.

@oke-aditya
Copy link

oke-aditya commented May 3, 2020

Add this in your CMakeLists.txt file before find_package(Torch REQUIRED)
set(CMAKE_PREFIX_PATH "libtorch/share/cmake/Torch")

Which should point to where Torch is unzipped appropriately.
Please update the docs. This issue is quite prelevant.

@glaringlee
Copy link
Contributor

glaringlee commented May 4, 2020

@oke-aditya
The doc is here https://pytorch.org/cppdocs/installing.html
we ask user to build libtorch using the following:
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=/absolute/path/to/libtorch ..
cmake --build . --config Release

People might put their libtorch unzipped files in different folders, so it might be better to ask them specify it when doing cmake.

@oke-aditya
Copy link

set(Torch_DIR /usr/local/Cellar/libtorch/share/cmake/Torch)
Set the Torch_DIR to where TorchConfig.cmake is. @ziyuang

Can this be added to docs. For people who unzip it in different directory. So that they don't get confused. Like I got.

@glaringlee
Copy link
Contributor

@oke-aditya. Yes, we will update our doc with more details on building libtorch, thanks.

@linjiapro
Copy link

Oh wow, this thread is very helpful to fix my issue. libtorch folder is under ~/Project/ThirdParty/ for me. I am using visual studio code on ubuntu and have this in my CMake file:

list(APPEND CMAKE_PREFIX_PATH {PROJECT_SOURCE_DIR}/ThirdParty/libtorch/

However, the above does not work and Torch cannot be found. Following suggestions here, I get the above fixed by using absolute path, instead of {PROJECT_SOURCE_DIR}.

@NumesSanguis
Copy link

Can you try changing cmake -DCMAKE_PREFIX_PATH=../../libtorch .. to cmake -DCMAKE_PREFIX_PATH=$PWD/../../libtorch ..?

This $PWD/ did the trick for me on Ubuntu 18.04.

I was following the TorchScript guide to use a model in C++ and ran into the same problem as OP. Would be great if this solution could be added to the guide: https://pytorch.org/tutorials/advanced/cpp_export.html#depending-on-libtorch-and-building-the-application

@linjiapro
Copy link

Update on my previous post: it turns out that the make file can use {PROJECT_SOURCE_DIR}, but there has to be a dollar sign before it:

list(APPEND CMAKE_PREFIX_PATH ${PROJECT_SOURCE_DIR}/ThirdParty/libtorch/

Oh wow, this thread is very helpful to fix my issue. libtorch folder is under ~/Project/ThirdParty/ for me. I am using visual studio code on ubuntu and have this in my CMake file:

list(APPEND CMAKE_PREFIX_PATH {PROJECT_SOURCE_DIR}/ThirdParty/libtorch/

However, the above does not work and Torch cannot be found. Following suggestions here, I get the above fixed by using absolute path, instead of {PROJECT_SOURCE_DIR}.

@wangleiofficial
Copy link

wangleiofficial commented Dec 27, 2020

hello, i found the same problem on the test case. @peterjc123 Is there any solution?:

-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++.exe
-- Check for working CXX compiler: /usr/bin/c++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Could NOT find torch (missing: TORCH_LIBRARY)
TORCH_LIBRARIES: torch;torch_library;C10_LIBRARY-NOTFOUND
CMake Error at CMakeLists.txt:7 (target_link_libraries):
  Cannot specify link libraries for target "dcgan" which is not built by this
  project.

OS: win10
ide: Clion
cmake: 3.14
Cygwin
and CMAKElists:

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(dcgan)
set(CMAKE_PREFIX_PATH "D:/cpp_extension/libtorch-win-shared-with-deps-debug-1.5.1+cpu/libtorch")
find_package(Torch REQUIRED)
message("TORCH_LIBRARIES: ${TORCH_LIBRARIES}")

target_link_libraries(dcgan "${TORCH_LIBRARIES}")
add_executable(dcgan dcgan.cpp)

I found the reason for error: https://discuss.pytorch.org/t/pytorch-c-libs-on-windows-abi-error/42008, libtorch only supports MSVC

@DineshRajanT
Copy link

DineshRajanT commented Jan 14, 2021

@goldsborough I meet the same problem today when I try to use the cpp api in my Macos. What I've done is:

cmake_minimum_required(VERSION 3.12)
project(torch_cpp_api_test)

set(CMAKE_CXX_STANDARD 17)

find_package(Torch REQUIRED)

set(SOURCE_FILES main.cpp)

target_link_libraries(torch_cpp_api_test "${TORCH_LIBRARIES}")

add_executable(torch_cpp_api_test ${SOURCE_FILES})
  • And I got the sad message:
CMake Error at CMakeLists.txt:6 (find_package):
  By not providing "FindTorch.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Torch", but
  CMake did not find one.

  Could not find a package configuration file provided by "Torch" with any of
  the following names:

    TorchConfig.cmake
    torch-config.cmake

  Add the installation prefix of "Torch" to CMAKE_PREFIX_PATH or set
  "Torch_DIR" to a directory containing one of the above files.  If "Torch"
  provides a separate development package or SDK, be sure it has been
  installed.

I really don't know how to do as I'm not very familiar with cmake.

New:
Finally I solved this problem by adding /path/to/libtorch to PATH.

I am getting the same error even after setting the path @goldsborough
NOTE: I am using Windows machine

@Gaop970222
Copy link

I solved it. You must put the libtorch to your project dir. libtorch can be get in pytorch official website. Then you need to add a sentence to your cmakelists.txt:

set(Torch_DIR "libtorch/share/cmake/Torch")

The problem can be addressed

@mirrortower
Copy link

I solved it. You must put the libtorch to your project dir. libtorch can be get in pytorch official website. Then you need to add a sentence to your cmakelists.txt:

set(Torch_DIR "libtorch/share/cmake/Torch")

The problem can be addressed

I encountered the same problem, and it simply works for me.

@XiangL-Xr
Copy link

XiangL-Xr commented Nov 16, 2021

Solution: export Torch_DIR as env variable before cmake,
if you don't install pytorch via pip or conda, please install first, then run:
$ mkdir build
$ cd build
$ cmake -DCMAKE_PREFIX_PATH=/home/anaconda3/envs/adop/lib/python3.8/site-packages/torch/share/cmake/Torch/ ..
$ make
The problem can be solved!

@zh794390558
Copy link

@XiangL-Xr It works for me

@fucker007
Copy link

Solution: export Torch_DIR as env variable before cmake, if you don't install pytorch via pip or conda, please install first, then run: $ mkdir build $ cd build $ cmake -DCMAKE_PREFIX_PATH=/home/anaconda3/envs/adop/lib/python3.8/site-packages/torch/share/cmake/Torch/ .. $ make The problem can be solved!

I really don't want to download libtorch, thanks your sovlution..

@wcneill
Copy link

wcneill commented Jun 9, 2023

set(Torch_DIR /usr/local/Cellar/libtorch/share/cmake/Torch) Set the Torch_DIR to where TorchConfig.cmake is. @ziyuang

Since the libtorch installation docs are still not updated, can you please enlighten those of us that found your answer with some details?

  • How did you come up with the variable Torch_DIR?
  • Where is it used and what is it used for?

If I understand correctly, set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/includes/libtorch") sets the variable used by CMake to resolve a package location when using find_package(Torch REQUIRED).

Although your solution works, I have no idea why and I don't think that's a good thing.

@godofecht
Copy link

`PS C:\Users\abhis\dev\DASP-CPP\build> cmake -DCMAKE_PREFIX_PATH=C:/Users/abhis/Downloads/libtorch-shared-with-deps-latest/libtorch/ ..
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.22621.
-- The C compiler identification is MSVC 19.35.32216.1
-- The CXX compiler identification is MSVC 19.35.32216.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at C:/Users/abhis/Downloads/libtorch-shared-with-deps-latest/libtorch/share/cmake/Torch/TorchConfig.cmake:22 (message):
static library c10_LIBRARY-NOTFOUND not found.
Call Stack (most recent call first):
C:/Users/abhis/Downloads/libtorch-shared-with-deps-latest/libtorch/share/cmake/Torch/TorchConfig.cmake:70 (append_torchlib_if_found)
CMakeLists.txt:4 (find_package)

CMake Error at C:/Program Files/CMake/share/cmake-3.30/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
Could NOT find Torch (missing: TORCH_LIBRARY)
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.30/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
C:/Users/abhis/Downloads/libtorch-shared-with-deps-latest/libtorch/share/cmake/Torch/TorchConfig.cmake:162 (find_package_handle_standard_args)
CMakeLists.txt:4 (find_package)
`

Seems I'm still facing the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: cpp-extensions Related to torch.utils.cpp_extension triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests