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

Hi,

After building the pre-abi libtorch from source using gcc 5.4.0,
using the following steps

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 && cd build_libtorch
python ../tools/build_libtorch.py

# Disable gcc 5.4.0 to use 4.8.2
unset CC && unset CXX && export LD_LIBRARY_PATH=$LD_LIBRARY_PATH_BACKUP

Then after switching to an older gcc 4.8.2, the command ldd libtorch.so throws some errors :

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)

I also tried with no success to hardcode the value of D_GLIBCXX_USE_CXX11_ABI to 0 in the pytorch/CMakeLists.txt:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
# or
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)

OS used: Centos 7

The distribution pre-abi provided by pytorch: https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-1.6.0%2Bcpu.zip doesn’t have this issue.

Any idea how to solve this ?

Regards,

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

1 Like

Hi Charles, thanks for the reply.
But i’m not sure why i have to, since with my gcc 4.8.2 i don’t see the CXXABI_* and GLIBCXX_* not found error using the Pre-cxx11 ABI libtorch distribution (v1.6.0) libtorch-shared-with-deps-1.6.0%2Bcpu.zip on Pytorch website which is compiled with gcc 7.3.1

Solution: https://github.com/pytorch/pytorch/issues/45064#issuecomment-696466277