How to handle dual ABI in GCC 5?

I am trying to figure out how to overcome the problems with the double ABI introduced in GCC 5. However, I have failed. Here is a very simple example for reproducing errors. The version of GCC that I am using is 5.2. As you can see, my main function (in the main.cpp file) is pretty simple:

// main.cpp

#include <iostream>
#include <string>

int main()
{
    std::string message = "SUCCESS!";
    std::cout << message << std::endl;
}

When i type

/home/aleph/gcc/5.2.0/bin/g++ main.cpp

The following error message appears:

/tmp/ccjsTADd.o: In function `main':
main.cpp:(.text+0x26): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
main.cpp:(.text+0x43): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
main.cpp:(.text+0x5c): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
main.cpp:(.text+0x8c): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
collect2: erreur: ld a retourné 1 code d'état d'exécution

If I change the value _GLIBCXX_USE_CXX11_ABIto 0, the problem will disappear.

But how to make work work with ABI by default?

EDIT: simpler question (remote cmake script)

+4
source share
1 answer

, gcc (-v flag). , gcc , libstd++. , - :

/home/aleph/gcc/5.2.0/bin/g++ -L /home/aleph/gcc/5.2.0/lib64 main.cpp

. .

./a.out

:

./a.out: relocation error: ./a.out: symbol _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1EPKcRKS3_, version GLIBCXX_3.4.21 not defined in file libstdc++.so.6 with link time reference

, , libstd++,

ldd a.out

- :

linux-vdso.so.1 =>  (0x00007ffebb722000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x0000003a71400000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x0000003d03a00000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x0000003a71000000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x0000003d02e00000)
/lib64/ld-linux-x86-64.so.2 (0x0000003d02a00000)

LD_LIBRARY_PATH libstd++, :

LD_LIBRARY_PATH=/home/aleph/gcc/5.2.0/lib64 ./a.out

, !

EDIT: , rpath LD_LIBRARY_PATH. CMake script.

project (example CXX)

add_executable(main main.cpp)

if(GCC_ROOT)
    set(CMAKE_CXX_COMPILER ${GCC_ROOT}/bin/g++)
    target_link_libraries(main ${GCC_ROOT}/lib64/libstdc++.so)
    link_directories(${GCC_ROOT}/lib64)
endif(GCC_ROOT)

script

cmake ..
make

'build'. , GCC:

cmake -D GCC_ROOT=/home/aleph/gcc/5.2.0 ..
make

script , libstd++ GCC-.

+5

Source: https://habr.com/ru/post/1614271/


All Articles