Support for C ++ 11 in g ++ without library functions `-std = C ++ 11`

Is there any way to tell g++ to enable the new C ++ 11 language features without any changes to the C ++ standard library due to ABI modifications?

Adding the compilation flag -std=c++11 tells g++ to include both the language and library functions, but the object files created in this way cannot be reliably linked to those that used the other -std= parameter. I would like to be able to use language enhancements such as rvalue references, move constructors (for my own classes) and the auto keyword in the code associated with C ++ 03 libraries.

EDIT:

I am interested in enabling g++ to enable its C ++ 11 language features, but I want it to analyze, compile and link the old C ++ 03 libraries. I do not want it to use the version of the standard C ++ 11 library. This means that in my own code I can use the auto , range foreach constructors, rvalue references, etc., but I can’t use the new C ++ 11 features in the standard C ++ library like std::move or extensions rvalue-ref for STL containers. The reason that the C ++ 11 standard library version is not needed is because the layout of the various objects has changed, so it is not valid for linking two object files that expect different versions of the standard library to be in the same binary file.

+6
source share
2 answers

No, you cannot enable the features of C ++ 11 without the capabilities of the C ++ 11 library (not without editing the libstdC ++ headers to remove all C ++ 11 components).

But there are not many incompatible characters (unless you are using 4.7.0 or 4.7.1 that had an incompatible std::list , true for 4.7.2), so you probably only need to worry about erase() members of RB containers -tree. You can make sure that the C ++ 11 version of the symbol is defined in your main executable, so that the version of the symbol will be used by all the code that needs it. Code in other libraries awaiting C ++ 03 will ignore the return value, code expecting C ++ 11 versions to use the return value.

+2
source

As far as I know, GCC 4.7 and above have ABI modifications. You can try the options below.

It may also help to use -std=gnu++11 instead of -std=c++11 . Why exactly I do not know, but it worked for me.

0
source

All Articles