mardi 3 novembre 2015

How to handle dual ABI in GCC 5?

I try to understand how to overcome problems with the dual ABI introduced in GCC 5. However, I don't manage to do it. Here is a very simple example to reproduce errors. The version of GCC I use is 5.2. As you can see, my main function (in main.cpp file) is quite simple:

// main.cpp

#include <iostream>
#include <string>

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

I use CMake to compile and link the code. The configuration script (CMakeLists.txt) is the following:

# CMakeLists.txt

project (example CXX)

add_executable(main main.cpp)

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

Here, one can notice I try to force compiler and LD_LIBRARY_PATH from an input GCC_ROOT which is supposed to contain the path to a GCC distribution.

To reproduce the problem, you just have to follow this step:

  1. create main.cpp and CMakeLists.txt in the same directory
  2. create a subdirectory 'build' and change to it
  3. type 'cmake -D GCC_ROOT=/path/to/your/gcc ..', where the path to you GCC distribution must contain subdirectories bin and lib.
  4. type 'make'
  5. type "./main"

For example, I type

cmake -D GCC_ROOT=/home/aleph/gcc/4.9.2 ..
make
./main

and everything works well! But, if I type

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

I get the following error message:

CMakeFiles/main.dir/main.cpp.o: In function main': main.cpp:(.text+0x26): undefined reference tostd::__cxx11::basic_string, std::allocator >::basic_string(char const*, std::allocator 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 tostd::__cxx11::basic_string, std::allocator >::~basic_string()' main.cpp:(.text+0x8c): undefined reference to `std::__cxx11::basic_string, std::allocator >::~basic_string()'

I tried to add these flags

SET( CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} 
                       --with-default-libstdcxx-abi=c++98 
                       --disable-libstdcxx-dual-abi" )

but they are not recognized.

Do you know how to solve this problem?

Aucun commentaire:

Enregistrer un commentaire