How do I make g++ 10 my default c++ compiler [duplicate]
I am trying to change the C++ compiler version. I have both, 4.6.x AND 4.4 versions, I want to set it to the 4.4 version, so I am doing:
export "CXX=g++-4.4"
But when I run the command:
g++ -v
I am still getting this:
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
I am using Ubuntu 14.04.
I am using this tutorial:
https://stackoverflow.com/questions/7832892/how-to-change-the-default-gcc-compiler-in-ubuntu
Solution 1:
The CXX
variable doesn't affect how the shell resolves program name g++
: that just follows the usual conventions of your executable search path $PATH
, and is finally determined by a symbolic link e.g. on my 14.04 system
$ which g++
/usr/bin/g++
while
$ ls -l $(which g++)
lrwxrwxrwx 1 root root 7 Apr 7 2014 /usr/bin/g++ -> g++-4.8
If you want to change that, you will need to re-make the symbolic link either manually e.g.
sudo ln -sf g++-4.4 /usr/bin/g++
or using the update-alternatives mechanism.
However, many build processes will respect the setting of CXX
(and the equivalent CC
for the C compiler, FC
for the Fortran compiler and so on) so that there is often no need to change the default compiler(s) via symlinks: if there is a particular software build that you are having difficulty with then I suggest you post a question about that specifically.