打开Synaptic Package Manager(System->Administration->Synaptic Package Manager)
Ubuntu10.10的Synaptic软件包管理器中只有gcc4.3和gcc4.4以及g++4.3和g++4.4几个版本的gcc编译器,将这几个包都安装上
在Synaptic软件包管理器中查看g++和gcc两个软件包安装的文件的路径如下:
(单击选中包,右击弹出快捷菜单,选择Properties,查看选项卡Installed Files)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
g++
/.
/usr
/usr/bin
/usr/bin/g++
/usr/bin/i686-linux-gnu-g++
/usr/share
/usr/share/doc
/usr/share/doc/g++
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/g++.1.gz
/usr/share/man/man1/i686-linux-gnu-g++.1.gz
-----------------------------------------------------
gcc
/.
/usr
/usr/bin
/usr/bin/c89-gcc
/usr/bin/c99-gcc
/usr/bin/gcc
/usr/bin/gcov
/usr/bin/i686-linux-gnu-gcc
/usr/share
/usr/share/doc
/usr/share/doc/cpp
/usr/share/doc/cpp/README.Bugs
/usr/share/doc/gcc
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/c89-gcc.1.gz
/usr/share/man/man1/c99-gcc.1.gz
/usr/share/man/man1/gcc.1.gz
/usr/share/man/man1/gcov.1.gz
/usr/share/man/man1/i686-linux-gnu-gcc.1.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++
执行如下两条命令,分别查看g++和gcc安装的文件:
命令1:
ls /usr/bin/g++ \
/usr/bin/i686-linux-gnu-g++ \
/usr/share/doc/g++ \
/usr/share/man/man1/g++.1.gz \
/usr/share/man/man1/i686-linux-gnu-g++.1.gz -li
结果:
126060 lrwxrwxrwx 1 root root 7 2010-12-24 15:23 /usr/bin/g++ -> g++-4.4
126017 lrwxrwxrwx 1 root root 7 2010-12-24 15:23 /usr/bin/i686-linux-gnu-g++ -> g++-4.4
228901 lrwxrwxrwx 1 root root 3 2010-12-24 03:12 /usr/share/doc/g++ -> cpp
425055 lrwxrwxrwx 1 root root 12 2010-12-24 03:12 /usr/share/man/man1/g++.1.gz -> g++-4.4.1.gz
424346 lrwxrwxrwx 1 root root 12 2010-12-24 03:12 /usr/share/man/man1/i686-linux-gnu-g++.1.gz -> g++-4.4.1.gz
-----------------------------------------------------
命令2:
ls /usr/bin/c89-gcc \
/usr/bin/c99-gcc \
/usr/bin/gcc \
/usr/bin/gcov \
/usr/bin/i686-linux-gnu-gcc \
/usr/share/doc/cpp/README.Bugs \
/usr/share/doc/gcc \
/usr/share/man/man1/c89-gcc.1.gz \
/usr/share/man/man1/c99-gcc.1.gz \
/usr/share/man/man1/gcc.1.gz \
/usr/share/man/man1/gcov.1.gz \
/usr/share/man/man1/i686-linux-gnu-gcc.1.gz -li
结果:
123433 -rwxr-xr-x 1 root root 428 2009-06-13 00:05 /usr/bin/c89-gcc
125908 -rwxr-xr-x 1 root root 451 2009-06-13 00:05 /usr/bin/c99-gcc
126000 lrwxrwxrwx 1 root root 7 2010-12-24 15:23 /usr/bin/gcc -> gcc-4.4
125909 lrwxrwxrwx 1 root root 8 2010-12-24 15:23 /usr/bin/gcov -> gcov-4.4
125999 lrwxrwxrwx 1 root root 7 2010-12-24 15:23 /usr/bin/i686-linux-gnu-gcc -> gcc-4.4
238784 lrwxrwxrwx 1 root root 22 2010-12-24 03:12 /usr/share/doc/cpp/README.Bugs -> ../gcc-4.4/README.Bugs
228900 lrwxrwxrwx 1 root root 3 2010-12-24 03:12 /usr/share/doc/gcc -> cpp
424133 -rw-r--r-- 1 root root 1365 2009-06-13 00:05 /usr/share/man/man1/c89-gcc.1.gz
420067 -rw-r--r-- 1 root root 1421 2010-05-19 18:33 /usr/share/man/man1/c99-gcc.1.gz
424209 lrwxrwxrwx 1 root root 12 2010-12-24 03:12 /usr/share/man/man1/gcc.1.gz -> gcc-4.4.1.gz
424134 lrwxrwxrwx 1 root root 13 2010-12-24 03:12 /usr/share/man/man1/gcov.1.gz -> gcov-4.4.1.gz
424208 lrwxrwxrwx 1 root root 12 2010-12-24 03:12 /usr/share/man/man1/i686-linux-gnu-gcc.1.gz -> gcc-4.4.1.gz
-----------------------------------------------------
发现其实g++包和gcc包都只是安装了一些链接,真正安装的编译器文件都在g++-4.3 , g++-4.4 或 gcc-4.3 , gcc-4.4包中
g++包和gcc包只是安装了一些链接文件,默认指向最新的版本,如果查看相应的系统文件夹,发现可以直接用g++-4.3命令代替g++就可以直接使用较低版本的编译器,所以如果为了编译特定软件,必须用较低版本的编译器的话,可以在编译时给参数设置一下就可以了,没有必要修改系统默认的编译器版本
如果确实要修改默认的编译器版本,只需将相应的链接修改即可
执行下面几条命令,只修改编译器的符号链接,文档的符号链接先不修改
sudo ln -sf g++-4.3 /usr/bin/g++
sudo ln -sf g++-4.3 /usr/bin/i686-linux-gnu-g++
sudo ln -sf gcc-4.3 /usr/bin/gcc
sudo ln -sf gcov-4.3 /usr/bin/gcov
sudo ln -sf gcc-4.3 /usr/bin/i686-linux-gnu-gcc
再执行命令 gcc --version 和 g++ --version 版本已经转成了较低的版本