gcc版本切换 ubuntu
2012-12-06 00:11
330 查看
f转自:http://www.metsky.com/archives/607.html
目前Ubuntu 12.04自带的GCC版本为4.6,遗憾的是在实际使用时,反而版本越高越好问题越多,所以,一旦遇到编译问题时最好先检查你下载的工程里的readme,默认的编译器版本是否为当前的安装版本,如果不是,就需注意很可能是版本兼容问题(甚至你可能是第一个遇到此BUG的幸运者),初步调试后即可尝试降低版本测试。
目前主流gcc版本有两个,一个是gcc4.4,一个是gcc4.6,下文介绍这两个版本切换和安装方法。
root@ubuntu:~# apt-get install build-essential
执行结果会自动安装最新的gcc4.6版本。
root@ubuntu:~# apt-get install gcc-4.4 g++-4.4 g++-4.4-multilib gcc-4.4-multilib
设置后,使用时需手动进行切换选择。
选择方法(根据编译器选择其一):
参考选择界面:
设置后,系统自动根据优先级选择,假设要设置gcc4.4优先于gcc4.6,设置方法如下:
设置完成后,gcc自动切换为使用4.4版本,因为上面设置4.4优先级高于4.6
gcc -v
示例输出:
view
source
print?
目前Ubuntu 12.04自带的GCC版本为4.6,遗憾的是在实际使用时,反而版本越高越好问题越多,所以,一旦遇到编译问题时最好先检查你下载的工程里的readme,默认的编译器版本是否为当前的安装版本,如果不是,就需注意很可能是版本兼容问题(甚至你可能是第一个遇到此BUG的幸运者),初步调试后即可尝试降低版本测试。
目前主流gcc版本有两个,一个是gcc4.4,一个是gcc4.6,下文介绍这两个版本切换和安装方法。
一、gcc 4.6安装
root@ubuntu:~# apt-get install build-essential执行结果会自动安装最新的gcc4.6版本。
二、gcc 4.4安装
root@ubuntu:~# apt-get install gcc-4.4 g++-4.4 g++-4.4-multilib gcc-4.4-multilib
三、设置gcc版本切换
1、手动切换
设置后,使用时需手动进行切换选择。1 | root@ubuntu:~# ls /usr/bin/gcc* -l |
2 | lrwxrwxrwx 1 root root 21 Sep 18 04:42 /usr/bin/gcc -> /etc/alternatives/gcc |
3 | -rwxr-xr-x 1 root root 224544 Apr 15 22:58 /usr/bin/gcc-4.4 |
4 | -rwxr-xr-x 1 root root 306200 Apr 15 19:45 /usr/bin/gcc-4.6 |
5 | root@ubuntu:~#update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 50 |
6 | root@ubuntu:~#update-alternatives --install /usr/bin/g++ gcc /usr/bin/g++-4.4 50 |
1 | root@ubuntu:~#update-alternatives --config gcc |
2 | root@ubuntu:~#update-alternatives --config g++ |
01 | root@ubuntu:~# update-alternatives --config g++ |
02 | There are 2 choices for the alternative g++ (providing /usr/bin/g++). |
03 |
04 | Selection Path Priority Status |
05 | ------------------------------------------------------------ |
06 | * 0 /usr/bin/g++-4.4 100 auto mode |
07 | 1 /usr/bin/g++-4.4 100 manual mode |
08 | 2 /usr/bin/g++-4.6 50 manual mode |
09 |
10 | Press enter to keep the current choice[*], or type selection number: 2 |
11 | update-alternatives: using /usr/bin/g++-4.6 to provide /usr/bin/g++ (g++) in manual mode. |
12 | root@ubuntu:~# |
2、设置优先级自动
设置后,系统自动根据优先级选择,假设要设置gcc4.4优先于gcc4.6,设置方法如下:1 | update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 100 |
2 | update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 50 |
3 | update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 100 |
4 | update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 50 |
5 | update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.4 100 |
6 | update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.6 50 |
四、查看生效的gcc版本
gcc -v示例输出:
view
source
print?
1 | root@ubuntu:~# gcc -v |
2 | Using built-in specs. |
3 | COLLECT_GCC=gcc |
4 | COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6/lto-wrapper |
5 | Target: i686-linux-gnu |
6 | Configured with: ../src/configure -v --with-pkgversion= 'Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file: ///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu |
7 | Thread model: posix |
8 | gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) |
9 | root@ubuntu:~# |
相关文章推荐
- ubuntu 14.04 命令行方式实现gcc升级及版本切换
- ubuntu 安装多套 gcc 和版本切换
- ubuntu系统的gcc版本切换
- Ubuntu gcc/g++ 版本切换
- ubuntu下手工切换gcc版本
- Ubuntu 14.04中升级gcc到版本4.9.2并切换使用它们
- ubuntu下手工切换gcc版本 .
- ubuntu下手工切换gcc版本
- ubuntu下多个gcc版本切换
- ubuntu多个gcc版本切换
- Ubuntu-gcc版本切换
- ubuntu14.04下多个GCC版本的切换
- Ubuntu: Linux系统下gcc(g++)任意版本切换
- Ubuntu下切换GCC版本
- ubuntu下gcc版本切换
- ubuntu下两个gcc版本切换
- Ubuntu16.04多个版本GCC编译器的安装和切换
- ubuntu下安装低级版本gcc/g++ 并随意切换
- Ubuntu下切换GCC版本
- Ubuntu 下切换gcc版本