3

I am trying to compile a program (using GCC 5.4.O) that depends on two libraries. Library A was compiled using the old ABI, while library B was compiled using the new C++11 ABI (see Dual ABI).

If compile the program setting _GLIBCXX_USE_CXX11_ABI 1, I have linking errors with library A. If I set it to 0, I have linking errors with library B.

Would it be possible to instruct the compiler to compile the calls to one library using one value of _GLIBCXX_USE_CXX11_ABI and the calls to the other library using another value of _GLIBCXX_USE_CXX11_ABI?

If I understood correctly, this is possible when compiling a new library that depends on two others but I don't know if the same is true for a program.

toliveira
  • 1,533
  • 16
  • 27

1 Answers1

2

Would it be possible to instruct the compiler to compile the calls to one library using one value of _GLIBCXX_USE_CXX11_ABI and the calls to the other library using another value of _GLIBCXX_USE_CXX11_ABI?

There is no way to tell the compiler to do that for you. It wouldn't work anyway, the old and new std::string types are incompatible, that's the whole point of having two different ABIs.

What you can do is manually make sure that all calls to library A happen from code which is compiled with _GLIBCXX_USE_CXX11_ABI=0 and all calls to library B happen from code which is compiled with _GLIBCXX_USE_CXX11_ABI=1. This implies that you can never make calls to both libraries from a single source file.

You would have to segregate all uses of library A and all uses of library B, and not pass std::string (or std::list) objects between those two parts of your program.

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521