I’m new to LibTorch and am currently learning how to use it. I have a few questions.
I want to be clear which directory should I add as a dependency, should I add libtorch/include or libtorch\include\torch\csrc\api\include?
In multiple tutorials on pytorch.org I saw multiple “one-stop” header, that’s very confusing.
Over here, it’s suggesting #include <torch/extension.h>, which doesn’t work for me when I add libtorch/include as dependency.
Over here, it suggests include<torch/script.h>.
And at here, it has a include<torch/torch.h> which I can’t even include from libtorch/include.
Can anyone give me any explanations, btw I’m using visual studio.
Thank you very much.
If you are intent on using visual studio id recommend to either use it with cmakelists or go through the cmake torchconfig to find all the relevant things to add.
From my experience torch.h gives you all the headers you will need!
But for completeness:
extension.h is just
#pragma once
// All pure C++ headers for the C++ frontend.
#include <torch/all.h>
// Python bindings for the C++ frontend (includes Python.h).
#include <torch/python.h>
Unfortunately I don’t. But if your question of the thread is answered, I would recommend to accept this one’s solution and open up a new thread for specific questions about pybind.
You don’t need to set the torch include dirs yourself. If cmake finds the torch package then its configuration will set those for you.
However, if this is all of your cmake code, then you’re lacking an include and a linking of the torch directories:
target_include_directories(example-app PUBLIC ${TORCH_INCLUDE_DIRS})
target_link_libraries(example-app PUBLIC ${TORCH_LIBRARIES})