vendredi 23 juin 2017

Can I link code compiled by g++-5 with object files made by g++-4?

Since g++-5, default C++ ABI has changed, in particular this affects std::string. I have some old object files made by g++ 4.5, which I need to link with code, which is to be compiled by g++ 5.2. But I can't seem to get the correct ABI option for g++-5. Here's a simple example to reproduce the problem:

First file:

// test45.cpp
#include <iostream>
void f(std::string const& s)
{
    std::cout << s << "\n";
}

Second file:

// test52.cpp
#include <string>
void f(std::string const&);
int main()
{
    f("Test string");
}

To reproduce the problem, compile as:

g++-4.5 test45.cpp -c
g++-5.2 test52.cpp -c
g++-5.2 test45.o test52.o -o test

I get an error:

test52.o: In function `main':
test52.cpp:(.text+0x41): undefined reference to `f(std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status

I've tried passing -fabi-version=... with ... being 0, 2, 4 — but g++-5.2 appears to emit calls to std::__cxx11::basic_string... functions instead of std::basic_string... ones, thus mismatching what test45.o expects.

Is there any way I could make g++-5 use a g++-4.5-compatible ABI for std::string and other library objects?

Aucun commentaire:

Enregistrer un commentaire