How can I force an older version of g++ if I have a newer version?
g++ --version
on my home machine reads 7.4.0
, but a server I frequently do work on shows 4.8.5
. Their servers don't support -std=c++11
compiler flags yet my home machine does. The most recent flag it does support is -std=c++0x
.
However, sometimes when I write code on my home machine, compile with -std=c++0x
flag without error, I will get errors if I brought it over to the server's local computers. Interestingly, SSHing to their servers does not show issues.
I'm not entirely sure what to make of this, I'm thinking my local machine may be ignoring the -std=c++0x
flag because I have a newer version. Is there a way to force a specific version?
If it makes any difference, I am using Windows 10 with LXSS (Ubuntu) and the server I am connecting to is using Redhat.
Open the terminal in Ubuntu and type:
sudo apt install g++-4.8
This command installs g++ version 4.8.5 in Ubuntu, the same version that is installed on your server.
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 40
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 60
sudo update-alternatives --config g++
After running sudo update-alternatives --config g++
a menu of g++ versions will appear and you will be asked to select the default g++ version as follows:
Press <enter> to keep the current choice[*], or type selection number:
Input a selection number from the menu and press Enter.
To change the default version of gcc follow the same procedure except replace all instances of g++ with gcc and replace the versions of g++ with the versions of gcc.