CXXABI_* and GLIBCXX_* not found after building pre-abi Libtorch from source using gcc 5.4.0

Marouane_Maatouk: <p>Hi,</p>
<p>After building the pre-abi libtorch from source using gcc 5.4.0,<br>
using the following steps</p>
<pre><code class="lang-auto">conda activate pytorch-build

# Setup compiler gcc 5.4.0 
export CC=~/gcc-5.4.0/bin/gcc
export CXX=~/gcc-5.4.0/bin/g++
export LD_LIBRARY_PATH_BACKUP=$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=~/gcc-5.4.0/lib64:$LD_LIBRARY_PATH

# Pytorch env variables
export BUILD_CAFFE2_MOBILE=OFF BUILD_TEST=OFF USE_OPENMP=0 USE_CUDA=0 USE_CUDNN=0 USE_MKLDNN=0 USE_MKL=0 USE_NNPACK=0 USE_QNNPACK=0 USE_DISTRIBUTED=0 USE_FFMPEG=0 USE_FBGEMM=0 USE_PYTORCH_QNNPACK=0
export PYTORCH_BUILD_VERSION=1.6.0 PYTORCH_BUILD_NUMBER=0
export _GLIBCXX_USE_CXX11_ABI=0

# Build libtorch
cd ~/Repos/pytorch
git checkout v1.6.0
python setup.py clean
mkdir -p build_libtorch &amp;&amp; cd build_libtorch
python ../tools/build_libtorch.py

# Disable gcc 5.4.0 to use 4.8.2
unset CC &amp;&amp; unset CXX &amp;&amp; export LD_LIBRARY_PATH=$LD_LIBRARY_PATH_BACKUP
</code></pre>
<p>Then after switching to an older gcc 4.8.2, the command <code>ldd libtorch.so</code> throws some errors :</p>
<pre><code class="lang-auto">build/lib/libtorch.so: /.../gcc/4.8.2/lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /.../pytorch/build_libtorch/build/lib/libtorch_cpu.so)
build/lib/libtorch.so: /.../gcc/4.8.2/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /.../pytorch/build_libtorch/build/lib/libtorch_cpu.so)
build/lib/libtorch.so: /.../gcc/4.8.2/lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /.../pytorch/build_libtorch/build/lib/libtorch_cpu.so)
build/lib/libtorch.so: /.../gcc/4.8.2/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /.../pytorch/build_libtorch/build/lib/libtorch_cpu.so)
build/lib/libtorch.so: /.../gcc/4.8.2/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /.../pytorch/build_libtorch/build/lib/libc10.so)
build/lib/libtorch.so: /.../gcc/4.8.2/lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /.../pytorch/build_libtorch/build/lib/libc10.so)
build/lib/libtorch.so: /.../gcc/4.8.2/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /.../pytorch/build_libtorch/build/lib/libc10.so)
</code></pre>
<p>I also tried with no success to hardcode the value of D_GLIBCXX_USE_CXX11_ABI to 0 in the <code>pytorch/CMakeLists.txt</code>:</p>
<pre><code class="lang-auto">set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
# or
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
</code></pre>
<p>OS used: Centos 7</p>
<p>The distribution pre-abi provided by pytorch: <a href="https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-1.6.0%2Bcpu.zip" rel="nofollow noopener">https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-1.6.0%2Bcpu.zip</a> doesn’t have this issue.</p>
<p>Any idea how to solve this ?</p>
<p>Regards,</p>

copythatpasta: <p>Your compiler is too old my friend. You need to bump down to v1.3.0 maximum as that’s the last one with only c++11 support. Above that it uses c++14 which your compiler does not support</p>

Marouane_Maatouk: <p>Hi Charles, thanks for the reply.<br>
But i’m not sure why i have to, since with my gcc 4.8.2 i don’t see the <code>CXXABI_* and GLIBCXX_* not found</code> error using the Pre-cxx11 ABI libtorch distribution <em>(v1.6.0)</em> <a href="https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-1.6.0%2Bcpu.zip" rel="nofollow noopener">libtorch-shared-with-deps-1.6.0%2Bcpu.zip</a> on Pytorch website which is compiled with gcc 7.3.1</p>

Marouane_Maatouk: <p>Solution: <a href="https://github.com/pytorch/pytorch/issues/45064#issuecomment-696466277" rel="nofollow noopener">https://github.com/pytorch/pytorch/issues/45064#issuecomment-696466277</a></p>