ubuntu 選擇gcc 版本

http://stackoverflow.com/questions/7832892/how-to-change-the-default-gcc-compiler-in-ubuntu

To figure out the current priorities of gcc, type in the command pointed out by @tripleee's comment:

查看當前的可切換的版本: update-alternatives --query gcc
例如有 4.6 4.5 兩個版本
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 100
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.5 50
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 100
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.5 50
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.6 100
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.5 50
設置爲4.5

update-alternatives --set g++ /usr/bin/g++-4.5update-alternatives --set gcc /usr/bin/gcc-4.5update-alternatives --set cpp-bin /usr/bin/cpp-4.5

Here, 4.6 is still the default (aka "auto mode"), but I explicitly switch to 4.5 temporarily (manual mode). To go back to 4.6:

update-alternatives --auto g++
update-alternatives --auto gcc
update-alternatives --auto cpp-bin

方法二:

echo 'export CXX=/usr/bin/gcc-4.5' >> ~/.bashrc
移除當前的選擇可以這樣

First erased the current update-alternatives setup for gcc and g++:

sudo update-alternatives --remove-all gcc 
sudo update-alternatives --remove-all g++

Install PackagesIt seems that both gcc-4.3 and gcc-4.4 are installed after install build-essential. However, we can explicitly install the following packages:sudo apt-get install gcc-4.3 gcc-4.4 g++-4.3 g++-4.4

First erased the current update-alternatives setup for gcc and g++: sudo update-alternatives --remove-all gcc sudo update-alternatives --remove-all g++ Install Packages It seems that both gcc-4.3 and gcc-4.4 are installed after install build-essential. However, we can explicitly install the following packages: sudo apt-get install gcc-4.3 gcc-4.4 g++-4.3 g++-4.4

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章