cmake: undefined reference to std::__cxx11::basic_string

The default version of gcc in the Arch Linux repositories is now gcc10:

➜  ~ pacman -Qo /usr/bin/c++
/usr/bin/c++ is owned by gcc 10.1.0-2

This can result in errors during linking while building packages, such as:

[ 75%] Linking CXX executable ../../../../../bin/sst_conn_tool
/usr/bin/ld: ../../../../../lib/libadios2_core.so.2.6.0: undefined reference to `int adios2::format::DataManSerializer::GetData<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<unsigned long, std::allocator<unsigned long> > const&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, std::vector<unsigned long, std::allocator<unsigned long> > const&, std::vector<unsigned long, std::allocator<unsigned long> > const&)'
/usr/bin/ld: ../../../../../lib/libadios2_core.so.2.6.0: undefined reference to `int adios2::format::DataManSerializer::GetData<float>(float*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<unsigned long, std::allocator<unsigned long> > const&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, std::vector<unsigned long, std::allocator<unsigned long> > const&, std::vector<unsigned long, std::allocator<unsigned long> > const&)'

This issue can be resolved by compiling with an earlier version of gcc:

➜  ~ pacman -Qo /usr/bin/g++-9
/usr/bin/g++-9 is owned by gcc9 9.3.0-3

Setting these CMake variables will result in using the gcc9 version of gcc, g++, gcc-ar, and gcc-ranlib:

        -DCMAKE_CXX_COMPILER=/usr/bin/g++-9 \
        -DCMAKE_CXX_COMPILER_AR=/usr/bin/gcc-ar-9 \
        -DCMAKE_CXX_COMPILER_RANLIB=/usr/bin/gcc-ranlib-9 \
        -DCMAKE_C_COMPILER=/usr/bin/gcc-9 \
        -DCMAKE_C_COMPILER_AR=/usr/bin/gcc-ar-9 \
        -DCMAKE_C_COMPILER_RANLIB=/usr/bin/gcc-ranlib-9 \

Leave a Reply

Your email address will not be published. Required fields are marked *