Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixing different C++ standards with GCC

Tags:

c++

gcc

c++11

c++98

I have the following scenario:

There are two components one is written in C++11 the other in C++98. Both are compiled from scratch using the same GCC 4.9. One uses the implicit default --std=gnu++98 the other explicitly sets --std=c++11.

Even after doing some research I could not completely answer the question if this could cause issues.

The GCC wiki says:

The C++98 language is ABI-compatible with the C++11 language, but several places in the library break compatibility. This makes it dangerous to link C++98 objects with C++11 objects. If you can recompile your code in matching versions of the language, you should do that.

This suggest that problems are to be expected.

So the questions are:

  1. Are there issues if the two components built with --std=gnu++98 and --std=c++11 are linked together, even tough they use same libstdc++ and are built with the same compiler (GCC 4.9)?

  2. Does Dual ABI support form GCC 5.1 have an influence in that case?

like image 545
Pascal Avatar asked Jun 27 '16 14:06

Pascal


People also ask

What C standard does GCC use?

2.3 Objective-C and Objective-C++ Languages GCC supports Objective-C++ and features available in Objective-C are also available in Objective-C++. GCC by default uses the GNU Objective-C runtime library, which is part of GCC and is not the same as the Apple/NeXT Objective-C runtime library used on Apple systems.

Does GCC 5.4 support C++17?

Compiler supportGCC has had complete support for C++17 language features since version 8. Clang 5 and later supports all C++17 language features.

Does GCC 11 support C++17?

C++17 Support in GCCThis mode is the default in GCC 11; it can be explicitly selected with the -std=c++17 command-line flag, or -std=gnu++17 to enable GNU extensions as well.

Does GCC support ANSI C?

GCC supports three versions of the C standard, although support for the most recent version is not yet complete. The original ANSI C standard (X3. 159-1989) was ratified in 1989 and published in 1990. This standard was ratified as an ISO standard (ISO/IEC 9899:1990) later in 1990.


1 Answers

1) There may be issues since, for example, the implementation of some part of the lib you mentioned changed.

2) Yes.

I would recompile everything in one of the two c++ version. If that is not an option (third party library etc.) using the dual ABI mechanism could be a solution. Be very careful on what it's shared between different version of the code.

The part of the wiki you mentioned talks about situations where, for example, old code tries to do stuff that is no longer supported (different semantic but same syntax).

like image 53
Robbykk Avatar answered Oct 19 '22 00:10

Robbykk