Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically select a C++11-compatible g++ version in the Makefile

The problem:

2 version of g++ installed on a computer running Ubuntu 12.04. They are the versions 4.6 and 5.2.

I have to compile a C++11 program using a Makefile. If I use g++ as compiler it calls automatically the version 4.6, it does not support c++11 so the compilation fails. I've followed a tutorial online, so that now if I call g++ it calls automatically the version 5.2 and now it works.

I find this solution not so good, since it works only on my PC. Is there a way to recognize in the Makefile if the default g++ version support C++11 and, in case not, switch to a more recent version?

Thank you!

like image 594
stefano1 Avatar asked Dec 15 '22 08:12

stefano1


1 Answers

Is there a way to recognize in the Makefile if the default g++ version support C++11 and, in case not, switch to a more recent version?

You can certainly detect the version of the default compiler available in PATH in your makefile. However, where do you search for another version?

The standard approach is to let the user specify the C compiler through CC and C++ compiler through CXX make variables, e.g.: make CC=/path/to/my/gcc CXX=/path/to/my/g++.

like image 123
Maxim Egorushkin Avatar answered Dec 28 '22 23:12

Maxim Egorushkin