2

Is it possible to define a piece of your code to be compiled with Cxx11 but the rest is using the compatibility ABI of libstdc++6 ?

Example:

// Compatibility ABI
int myvar = 0;
std::string mystring = "hello";

// This method is from another library
// that has been compiled with Cxx11
call_routine_ext_library(mystring);

// Compatibility ABI
myvar += 2;

My whole system is compiled in compatibility mode except one external library compiled with Cxx11. Does there exist a preprocessor that allows you to handpick certain part of your code to be compiled using the new ABI just as you would have defined D_GLIBCXX_USE_CXX11_ABI=1 on the compiler line ?

The error I get when calling the method call_routine_ext_library is:

undefined reference to `call_routine_ext_library(std::string const&)'

because the library contains this:

call_routine_ext_library(std::__cxx11::basic_string<char, std::char_traits<char>)

So I was hoping I could force the compiler to use Cxx11 mode when compiling the string I pass into that method. Are there any means of linking against a binary compiled with Cxx11 when your code is compiled without it ?

EinarMar
  • 45
  • 5
  • So - two compilers? Maybe it's best to make a C-level wrapper, and call via (eg) cdecl passing char*s etc. – David Jun 19 '15 at 15:33
  • @David M If you mean that does something like: `const char* tmpstr = mystring.c_str(); call_routine_ext_library(tmpstr)` then that doesn't work either – EinarMar Jun 19 '15 at 17:24
  • And `extern "C"`? So all C++ compilers link using C mode, not C++ or a specific C++ ABI? Are you familiar with [this advice on mixing C and C++](https://isocpp.org/wiki/faq/mixing-c-and-cpp)? – David Jun 22 '15 at 14:46

0 Answers0