Dears, I am trying to link pytorch statically with a cmake project. For that I am using FetchContent to download Pytorch 2.2.2 and make it available to be compiled as such:
CMakeLists.txt:
...
include(FetchContent)
set(FETCHCONTENT_QUIET FALSE)
FetchContent_Declare(torch
GIT_REPOSITORY https://github.com/pytorch/pytorch
GIT_TAG v2.2.2)
set(BUILD_SHARED_LIBS OFF)
set(USE_KINETO OFF)
FetchContent_MakeAvailable(torch)
# Manually list all .h and .cpp files for the plugin
set(SourceFiles
src/main.cpp
)
add_executable("${PROJECT_NAME}" ${SourceFiles})
target_link_libraries("${PROJECT_NAME}"
PRIVATE
torch
)
...
The issue is, once I invoke make, the pytorch library seems to be compiled however, I always see this linking error where ATen/Tensor.h is not found. Am I missing something on my cmake? Maybe include directories? Any help is appreciated.
Torch Build:
[ 35%] Linking CXX static library ../../../lib/libtorch_cpu.a
[ 35%] Built target torch_cpu
[ 35%] Building CXX object _deps/torch-build/caffe2/CMakeFiles/torch.dir/__/__/__/empty.cpp.o
[ 35%] Linking CXX static library ../../../lib/libtorch.a
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: ../../../lib/libtorch.a the table of contents is empty (no object file members in the library define global symbols)
[ 35%] Built target torch
Linker error:
In file included from /Users/caiomcg/Workspace/project/src/main.cpp:2:
In file included from /Users/caiomcg/Workspace/project/build/_deps/torch-src/torch/csrc/api/include/torch/torch.h:3:
In file included from /Users/caiomcg/Workspace/project/build/_deps/torch-src/torch/csrc/api/include/torch/all.h:7:
In file included from /Users/caiomcg/Workspace/project/build/_deps/torch-src/torch/csrc/api/include/torch/autograd.h:3:
In file included from /Users/caiomcg/Workspace/project/build/_deps/torch-src/c10/../torch/csrc/autograd/autograd.h:3:
In file included from /Users/caiomcg/Workspace/project/build/_deps/torch-src/c10/../torch/csrc/autograd/variable.h:6:
In file included from /Users/caiomcg/Workspace/project/build/_deps/torch-src/c10/../torch/csrc/autograd/cpp_hook.h:2:
/Users/caiomcg/Workspace/project/build/_deps/torch-src/c10/../torch/csrc/autograd/function_hook.h:3:10: fatal error: 'ATen/Tensor.h' file not found
#include <ATen/Tensor.h>