I’m trying to compile a minimal C++ torch test program. This is the code:
#include <torch/torch.h>
#include <iostream>
int main()
{
torch::Tensor tensor = torch::rand({2,3});
std::clog << tensor << std::endl;
}
The CMake files provided with source code don’t work well with my project, so I wrote a simple CMake. Nevertheless, the final command line to linker is:
/home/yangxi/software/clang+llvm-5.0.1-x86_64-linux-gnu-debian8/bin/clang++ -g -rdynamic CMakeFiles/test1.dir/test1.cpp.o -o test1 -Wl,-rpath,/home/yangxi/projects/TBTNativeCodingMegaProject/3rd_party/Torch/1.2.0/linux/lib /home/yangxi/projects/TBTNativeCodingMegaProject/3rd_party/Torch/1.2.0/linux/lib/libtorch.so sibling/treecore/src/libtreecore_dbg.a /home/yangxi/projects/TBTNativeCodingMegaProject/3rd_party/Torch/1.2.0/linux/lib/libcudart-1581fefa.so.10.0 /home/yangxi/projects/TBTNativeCodingMegaProject/3rd_party/Torch/1.2.0/linux/lib/libgomp-4f651535.so.1 /home/yangxi/projects/TBTNativeCodingMegaProject/3rd_party/Torch/1.2.0/linux/lib/libnvToolsExt-3965bdd0.so.1 /home/yangxi/projects/TBTNativeCodingMegaProject/3rd_party/Torch/1.2.0/linux/lib/libc10_cuda.so /home/yangxi/projects/TBTNativeCodingMegaProject/3rd_party/Torch/1.2.0/linux/lib/libc10.so -lpthread -ldl sibling/treecore/sibling/3rd_party/zlib/libzlib_static.a
It claims many linker errors about c10::Error constructor unresolved:
CMakeFiles/test1.dir/test1.cpp.o: In function `c10::backendToDeviceType(c10::Backend)':
/home/yangxi/projects/TBTNativeCodingMegaProject/3rd_party/Torch/1.2.0/linux/include/c10/core/Backend.h:169: undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/yangxi/projects/TBTNativeCodingMegaProject/3rd_party/Torch/1.2.0/linux/include/c10/core/Backend.h:171: undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
......
......
However, I can see the constructor by objdump -C -d /home/yangxi/projects/TBTNativeCodingMegaProject/3rd_party/Torch/1.2.0/linux/lib/libc10.so
, it is just there:
0000000000012ab0 <c10::Error::Error(c10::SourceLocation, std::string const&)@plt>:
12ab0: ff 25 ea 55 23 00 jmpq *0x2355ea(%rip) # 2480a0 <c10::Error::Error(c10::SourceLocation, std::string const&)@@Base+0x218080>
12ab6: 68 11 00 00 00 pushq $0x11
12abb: e9 d0 fe ff ff jmpq 12990 <.plt>
So I have no idea on how to solve the symbol…