Undefined reference to c10::Error::Error

username: yangxi
cooked: <p>I’m trying to compile a minimal C++ torch test program. This is the code:</p>
<pre><code class="lang-auto">#include &lt;torch/torch.h&gt;

#include &lt;iostream&gt;

int main()
{
    torch::Tensor tensor = torch::rand({2,3});
    std::clog &lt;&lt; tensor &lt;&lt; std::endl;
}
</code></pre>
<p>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:</p>
<pre><code class="lang-auto">/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 

</code></pre>
<p>It claims many linker errors about c10::Error constructor unresolved:</p>
<pre><code class="lang-auto">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&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
/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&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
......
......
</code></pre>
<p>However, I can see the constructor by <code>objdump -C -d /home/yangxi/projects/TBTNativeCodingMegaProject/3rd_party/Torch/1.2.0/linux/lib/libc10.so</code>, it is just there:</p>
<pre><code class="lang-auto">0000000000012ab0 &lt;c10::Error::Error(c10::SourceLocation, std::string const&amp;)@plt&gt;:
   12ab0:       ff 25 ea 55 23 00       jmpq   *0x2355ea(%rip)        # 2480a0 &lt;c10::Error::Error(c10::SourceLocation, std::string const&amp;)@@Base+0x218080&gt;
   12ab6:       68 11 00 00 00          pushq  $0x11
   12abb:       e9 d0 fe ff ff          jmpq   12990 &lt;.plt&gt;
</code></pre>
<p>So I have no idea on how to solve the symbol…</p>

username: yf225
cooked: <p>Your compiler expects cxx11 ABI symbol <code>std::__cxx11::basic_string</code>. We now have new ABI binaries for libtorch and they can be found on <a href="http://pytorch.org/" rel="nofollow noopener">http://pytorch.org</a>, or at <a href="https://github.com/pytorch/pytorch/issues/17492#issuecomment-524692441" rel="nofollow noopener">https://github.com/pytorch/pytorch/issues/17492#issuecomment-524692441</a>.</p>
<p>Alternatively, you can use your compiler to compile libtorch from scratch using instructions at <a href="https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst" rel="nofollow noopener">https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst</a>.</p>