Reputation: 584
I have a big autotools project, and one part of codes in the subdirectory use g++-4.9 to compile, others use g++8.2.
My question is how to compile the whole project with different version of g++.
I've see some related question is to change a different g++ compiler, and general answers are to set environment variables or make
options.
However, my issue is to compile with both g++8.2 and g++4.9 in same time.
I expect there are some solutions to set Makefile.am like :
noinst_PROGRAMS=foo bar
foo_CXX_COMPILER=/usr/bin/g++-4.9
bar_CXX_COMPILER=/usr/bin/g++-8.2
EDIT:
More Details that I've tried :
auto_ptr
is deprecated" when compiling with g++-4.9 -std=c++11
, but without any error and executing well. g++-4.9 -std=c++98
.g++-8.2
, even if I add the flag -std=c++98.
I guess this is because g++-8.2
compiler cannot recognize auto_ptr
usage!
I prefer to use only one compiler which makes the problem simply! But, if the case cannot be allowed to use only one, I would want to know how to set up Makefile.am with different two compilers, or any best way to solve this compilation problem !
Upvotes: 0
Views: 9042
Reputation: 1
I have a big autotools project, and one part of codes in the subdirectory use g++-4.9 to compile, others use g++8.2.
My question is how to compile the whole project with different version of g++.
I don't recommend doing that. The ABI conventions might have changed (so compiling with two different GCCs of different ABIs is IMHO not recommended).
Actually, I recommend building all the project with the same (newest) GCC, that is with g++
8.2
If some parts of the project are using an different dialect of C++, you could explicitly pass some -std=c++11
or -std=c++17
options to them.
So just configure your project to use the same (and latest) GCC. If some C++ dialects are different, pass a specific flag to it. See options controlling the C++ dialect and -std=
option.
At last, you could consider patching the source code of the old library to make it C++14 compliant (in particular, remove every occurrence of auto_ptr
and replace them wisely with unique_ptr
etc...). In most cases, it is worthwhile to do that (and perhaps a newer version of that old library already exists, which is C++14 or C++17)
Mixing two different versions of the C++ standard library is certainly painful and should be avoided. If you insist trying that, you need to understand painfully all the gory details (so I really recommend not trying this). Then read Drepper's How to write shared libraries paper.
Another approach could be to have your software use two different processes (one for the old C++98 source code, another for the new C++14 code) and use inter-process communication facilities. This is perhaps the most robust solution.
For practical purposes, consider old C++98 and new C++14 as two different, and incompatible, programming languages (C++11 was really different of its predecessors).
Upvotes: 2
Reputation: 16305
My question is how to compile the whole project with different version of g++.
It is possible, but I wouldn't recommend it. The GNU Build System doesn't have any support for that, but you might have a look at how AX_CC_FOR_BUILD accomplishes a similar idea (enabling a compiler for build as well as for host).
Idea #2 is what @JohnBollinger suggested -- pick a compiler and build with it. End users of your build will appreciate this more than having to setup two compilers. This is the solution I would go with, since the GNU Build System works this way. g++-8.2 can be told to compile code from previous versions of C++ if the old code can't be modernized for some reason.
Idea #3 is basically to split your project into two autotools projects -- one compiling with the old compiler and one with the new compiler. Not really a fan of this idea either.
Upvotes: 4