Whenever I try to build my CMakeLists.txt file, it says that "CMake Error at CMakeLists.txt:4 (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 do not know how to fix this. It would be really helpful if someone could help me.
I would recommend to follow this tutorial, which gives you a quick introduction to using libtorch.
As the tutorial and the error message explain, you should use:
root@fa350df05ecf:/home# mkdir build
root@fa350df05ecf:/home# cd build
root@fa350df05ecf:/home/build# cmake -DCMAKE_PREFIX_PATH=/path/to/libtorch ..
I get the same error as OP exactly when running cmake from the command line, as copied and pasted from the posted tutorial (Installing C++ Distributions of PyTorch).
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.
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.
Where is FindTorch.cmake located?
What is CMAKE_MODULE_PATH? An environment variable? A CMAKE variable we can set like set(CMAKE_MODULE_PATH "some/path/")
What is the installation “prefix” (in this specific case, but also generally), and is CMAKE_PREFIX_PATH a variable we set in CMakeLists.txt, or is it an environment variable?
I was getting the same error, despite following official the tutorial for installing libtorch. I was able to resolve it by adding the following line to my CMakeLists.txt: