Web 服务器 · 2012/11/15 1

Ubuntu 12.04下编译安装 GCC4.1.2

最近在了解分布式文件系统, 看到了淘宝自己的开源分布式文件系统 tfs, 因为他要求编译最好是使用 4.1.2 版本的 gcc 编译, 因此需要安装此版本的 gcc.
其他少说, 直接开始安装吧:

1. 下载&解压源码

$ wget http://ftp.gnu.org/gnu/gcc/gcc-4.1.2/gcc-4.1.2.tar.bz2
$ tar xvjf gcc-4.1.2.tar.bz2

2. 安装依赖库, 以及软件

$ sudo apt-get install libc6-dev libgmp-dev libmpfr-dev texinfo

3. 为头文件以及所需库添加链接
添加如下链接, 这取决于你的 Ubuntu 系统架构, 如果你使用的是64位的ubuntu系统应当使用x86_64-linux-gnu替代i386-linux-gnu

$ cd /usr/include
$ sudo ln -s i386-linux-gnu/bits bits
$ sudo ln -s i386-linux-gnu/gnu gnu
$ sudo ln -s i386-linux-gnu/sys sys
$ sudo ln -s i386-linux-gnu/asm asm
$ cd /usr/lib
$ sudo ln -s i386-linux-gnu/crt1.o crt1.o
$ sudo ln -s i386-linux-gnu/crti.o crti.o
$ sudo ln -s i386-linux-gnu/crtn.o crtn.o 

4. 编译gcc

$ cd gcc-4.1.2
$ mkdir build
$ cd build
$ ../configure --prefix=/usr/local --program-prefix=sse- --libexecdir=/usr/local/lib --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --disable-multilib --enable-languages=c,c++
$ make bootstrap

如果出现了如下错误:

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 bootstrap MAKEINFO=makeinfo

5. 安装gcc

$ make install
$ cd /usr/local/bin
$ ll *gcc*

看到类似以下几个文件, 安装就完成了

i686-pc-linux-gnu-gcc-4.1.2 i686-pc-linux-gnu-ssegcc ssegcc ssegccbug

参考文献: Building GCC 4.1.2 on Ubuntu 12.04.1 LTS