1.下载gcc4.1.2(http://gcc.gnu.org/)
2.解压(我是解压在/usr/local/src).建立文件夹/usr/local/gcc-4.1.2,为后来的安装做准备
3.#cd /usr/local/src/gcc-4.1.2
#./configure --prefix=/usr/local/gcc-4.1.2 --enable-threads=posix --disable-checking --with-system-zlib --enable-languages=c,c++ --host=x86_64-linux
#make
出现错误:
WARNING: `makeinfo' is missing on your system. You should only need it if
you modified a `.texi' or `.texinfo' file, or any other file
indirectly affecting the aspect of the manual. The spurious
call might also be the consequence of using a buggy `make' (AIX,
DU, IRIX). You might want to install the `Texinfo' package or
the `GNU make' package. Grab either from any GNU archive site.
make[3]: *** [fastjar.info] 错误 1
make[3]:正在离开目录 `/home/ssm/gcc-obj/fastjar'
make[2]: *** [all] 错误 2
make[2]:正在离开目录 `/home/ssm/gcc-obj/fastjar'
make[1]: *** [all-fastjar] 错误 2
make[1]:正在离开目录 `/home/ssm/gcc-obj'
make: *** [all] 错误 2
解决办法:安装texinfo(我安装的是texinfo4.12)
修改gcc-4.1.2的configure:
3551 if ${MAKEINFO} --version \
3552 | egrep 'texinfo[^0-9]*([1-3][0-9]|4\.[2-9]|[5-9])' >/dev/null 2>&1;then
将其中的4\.[2-9]|[5-9]改成4.\[1-9]|[1-9](因为我的是4.12)
重新make,又出现错误:
error: gnu/stubs-32.h: No such file or directory
解决办法:
Fix for Debian Linux
Type the following command:
$ sudo apt-get install libc6-dev
Fix for Ubuntu Linux
Type the following command:
$ sudo apt-get install libc6-dev-i386
Fix for OpenSUSE / Novell Suse Linux (SLES)
Type the following command:
# zypper in glibc-devel-32bit
Fix for RHEL / Fedora / CentOS / Scientific Linux
Type the following yum command to install glibc package:
# yum install glibc-devel.i686
4. make install
5.使用 update-alternatives 管理多版本共存的软件
首先添加 gcc 的配置管理
查看并选择gcc的不同版本#update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 50 #update-alternatives --install /usr/bin/gcc gcc /usr/local/gcc-4.1.2/bin/x86_64-linux-gcc-4.1.2 40
update-alternatives --config gcc
There are 2 alternatives which provide `gcc'.
Selection Alternative
-----------------------------------------------
+ 1 /usr/bin/gcc-4.3
* 2 /usr/local/gcc-4.1.2/bin/x86_64-linux-gcc-4.1.2
Press enter to keep the default[*], or type selection number:_
选择对应的就可以了。