Tag Archives: _G++_GLIBCXX_USE_CXX11_ABI

[Solved] Undefined reference_G++ _GLIBCXX_USE_CXX11_ ABI compilation error: STD:: Basic_String and STD::__cxx11::basic_String cannot match

1. Reason:

GCC 5 will compile STD:: string as per C + + 11 STD::__cxx11::basic_string< char> At this time, if the library you call does not enable the C + + 11 feature during compilation, the STD:: string in it is actually STD:: basic_string< char>, If the string under c + + 11 is passed as a parameter into a library other than C + + 11, error: cannot convert ‘const STD::__cxx11::basic_string< char>’ To ‘const char *’, or undefined reference

Enter GCC installation directory and enter  include/c++/5.4.0  Directory, and then view  x86_64 unknown Linux GNU/bits/C + + config.H, or key macro definitions in (/usr/include/x86_64 Linux GNU/C + +/5/bits/C + + config.H):

#if _GLIBCXX_USE_CXX11_ABI
namespace std
{
  inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { }
}
namespace __gnu_cxx
{
  inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { }
}
# define _GLIBCXX_NAMESPACE_CXX11 __cxx11::
# define _GLIBCXX_BEGIN_NAMESPACE_CXX11 namespace __cxx11 {
# define _GLIBCXX_END_NAMESPACE_CXX11 }
# define _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_ABI_TAG_CXX11
#else
# define _GLIBCXX_NAMESPACE_CXX11
# define _GLIBCXX_BEGIN_NAMESPACE_CXX11
# define _GLIBCXX_END_NAMESPACE_CXX11
# define _GLIBCXX_DEFAULT_ABI_TAG

Check bits/basic_string.h

#if _GLIBCXX_BEGIN_NAMESPACE_CXX11
// line 52~2441
_GLIBCXX_END_NAMESPACE_CXX11
#else  // !_GLIBCXX_USE_CXX11_ABI
  // Reference-counted COW string implentation
  // ...
#endif

That is, use the old version of GCC or – D_GLIBCXX_USE_CXX11_ABI = 0, STD:: string will use the old version of STD:: basic_string. However, when compiling with the new version of GCC, STD:: string will use STR::__cxx11::basic_string. Therefore, if the linked library uses different versions of GCC or the compilation options are different during compilation, the following errors will occur:

libboost_regex.so.1.72.0: undefined reference to `std::__cxx11::messages<char> const& std::use_facet<std::__cxx11::messages<char> >(std::locale const&)@GLIBCXX_3.4.21'

2. If string is not involved, you can simply use the library that implements code compilation by yourself. You can add cxx11 scope during compilation in the following ways:

#  define DUAL_ABI cxx11 __attribute__((abi_tag("cxx11")))

namespace ClassA {
  inline namespace DUAL_ABI {
    // library goes here
  }
}

This can solve problems like undefined reference to ` STD::_Cxx11:: funa() ` problem.

3. Otherwise, you can only use the corresponding compilation option or GCC version

4. View compile symbol commands

Strings view symbols and C + + filt explain symbols

strings libfuna.so | grep init
#_ZN12TensorRT_SDK4initESsi 
c++filt _ZN12TensorRT_SDK4initESsi
#TensorRT_SDK::init(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)