Libtorch CMakeLists.txt Building Error

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:


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

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 ..

to build the application.

Basically I am using CLion and I want to run the program from there. When I use the run feature, it says that the TorchConfig.cmake file is missing

I don’t know, if CLion can build cmake applications, as I’ve never used it.
If not, you would have to build it using the posted instruction.