Where to find <torch/torch.h>?

I succeed in compiling the code with cmake directly, but when I use vscode for editing, it always get error message with <torch/torch.h> not found. How can I get it?


you need to add the somewhat hidden <installation dir>/include/torch/csrc/api/include to the includes.
If you create the CMakeLists.txt as in the example, the TorchConfig.cmake should set it up for you up when running find_package(Torch REQUIRED).

Best regards



It’s works!!

Hi I am starting using Torch in c++ and I do not know what are you refering as adding the folder to the includes. Sorry if this is a very basic question.

It depends on how you compile your software.

If you use cmake you can do this in your CMakelist

find_package(Torch REQUIRED)
include_directories(SYSTEM ${TORCH_INCLUDE_DIRS})

hi, i create CMakeLists.txt as in the example and I do the configuration but appearing an error is : torch_dir not found ? what do i do for succeful compiling .

Add this line to your project’s CMakeLists.txt file.

set(CMAKE_PREFIX_PATH "<libtorch-path>/share/cmake/Torch")


After I linked <installation dir>/include/torch/csrc/api/include to the includes, with command line sudo ln -s /usr/local/Cellar/libtorch/1.6.0_1/include/torch/csrc/api/include/torch torch in the directory /usr/local/include, my vscode and ycm of vim still can’t work. Am I wrong?

I’m not sure symlinking is a good way to go about it, as you need several directories to be set up that contain torch (i.e. torch/include and torch/csrc/api/include).