GLIBC linker errors when linking against libtorch on Ubuntu 18.04

username: tiger17
cooked: <p>Hello,</p>
<p>I spent a few hours on this but stuck now. I’m getting these errors below when running make in my project:</p>
<p>/home/t/libtorch/lib/libgomp-753e6e92.so.1: undefined reference to `clock_gettime@GLIBC_2.17’</p>
<p>/home/t/libtorch/lib/libgomp-753e6e92.so.1: undefined reference to `clock_getres@GLIBC_2.17’</p>
<p>/home/t/libtorch/lib/libtorch.so: undefined reference to `memcpy@GLIBC_2.14’</p>
<p>/home/t/libtorch/lib/libtorch.so: undefined reference to `lgammaf@GLIBC_2.23’</p>
<p>/home/t/libtorch/lib/libtorch.so: undefined reference to `lgamma@GLIBC_2.23’</p>
<p>Thank you!</p>

username: yf225
cooked: <p><a class="mention" href="/u/tiger17">@tiger17</a> Could you provide us the output of <code>ldd --version</code> and <code>g++ --version</code>? And did you download the old-ABI version or new-ABI version of libtorch?</p>

username: tiger17
cooked: <p>Answering your questions:</p>
<p>ldd (Ubuntu GLIBC 2.27-3ubuntu1) 2.27</p>
<p>g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0</p>
<p><a href="https://download.pytorch.org/libtorch/cu100/libtorch-cxx11-abi-shared-with-deps-1.2.0.zip" class="onebox" target="_blank" rel="nofollow noopener">https://download.pytorch.org/libtorch/cu100/libtorch-cxx11-abi-shared-with-deps-1.2.0.zip</a></p>

username: tiger17
cooked: <p>Wondering if there are any updates on this?</p>

username: yf225
cooked: <p><a class="mention" href="/u/tiger17">@tiger17</a> Do you mind trying to compile libtorch from source following the instructions at <a href="https://github.com/pytorch/pytorch#from-source" rel="nofollow noopener">https://github.com/pytorch/pytorch#from-source</a>? Then you can link to the compiled libtorch using <code>cmake -DCMAKE_PREFIX_PATH=/absolute/path/to/pytorch/folder ..</code></p>

username: sailfish009
cooked: <aside class="quote no-group" data-username="tiger17" data-post="1" data-topic="55183">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/t/edb3f5/48.png" class="avatar"> tiger17:</div>
<blockquote>
<p>undefined reference to `clock_gettime@GLIBC</p>
</blockquote>
</aside>
<p>try add ‘-lrt’ to CMakeLists.txt</p>
<pre><code class="lang-auto">SET(GCC_COVERAGE_LINK_FLAGS    "-lrt")
</code></pre>

username: tiger17
cooked: <p>When compiling from source following the referenced page and in the new conda env,<br>
“python setup.py install” fails.</p>
<p>Part of error message:</p>
<p>Makefile:25: recipe for target ‘src.build’ failed</p>

username: tiger17
cooked: <p>I think I tried this already.</p>

username: Oktai15
cooked: <p>I got the same problem (<a class="mention" href="/u/tiger17">@tiger17</a>, <a class="mention" href="/u/yf225">@yf225</a>). What could we do with it? g++ version is 6.3.0 and ldd version is 2.24.</p>

username: Oktai15
cooked: <p><a class="mention" href="/u/tiger17">@tiger17</a>, you can find a solution here: <a href="https://github.com/pytorch/pytorch/issues/27834" rel="nofollow noopener">https://github.com/pytorch/pytorch/issues/27834</a></p>

username: Carol_Ye_Liu
cooked: <p><a class="mention" href="/u/tiger17">@tiger17</a> <a class="mention" href="/u/oktai15">@Oktai15</a>, I am having the same issue with libtorch nightly build only (<a href="https://download.pytorch.org/libtorch/nightly/cu101/libtorch-cxx11-abi-shared-with-deps-latest.zip" rel="nofollow noopener">https://download.pytorch.org/libtorch/nightly/cu101/libtorch-cxx11-abi-shared-with-deps-latest.zip</a>). What is the solution exactly? I checked issue 27834 and it seems like the solution is to change gcc compiler?</p>

username: tiger17
cooked: <p>Yes, changing compiler actually worked for me.</p>
<p>Specifically,<br>
export CC=/usr/bin/gcc<br>
export CXX=/usr/bin/g++</p>

username: Carol_Ye_Liu
cooked: <p><a class="mention" href="/u/tiger17">@tiger17</a> May I ask your gcc version?</p>