gcc-4.9.3 编译过程笔记

Tags:

官方的编译指南:https://gcc.gnu.org/install/

唠叨几句

之前升级了我的阿里云的gcc,记得是费了些功夫的,有些坑。可惜忘了记笔记。今天编译node.js时发现我编译的gcc有些问题,要重新编译下,悲催的是gcc的编译目录都删掉了。全部得重来过。

准备

https://gcc.gnu.org/mirrors.html下载源码包到机器上并解压:

wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-4.9.3/gcc-4.9.3.tar.gz

tar -xzvf gcc-4.9.3.tar.gz

配置

To configure GCC:

 % mkdir objdir
 % cd objdir
 % srcdir/configure [options] [target]

即,在gcc-4.9.3目录里建立objdir子目录,并在这个子目录里执行configure。

configure要填什么参数,这个因人而异了。就不说了。官方文档是https://gcc.gnu.org/install/configure.html

我只需要用c++,所以我执行了:

~/download/gcc-4.9.3/configure --enable-languages=c,c++

然后就遇到第一个坑:

坑1

configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+. Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify their locations. Source code for these libraries can be found at their respective hosting sites as well as at ftp://gcc.gnu.org/pub/gcc/infrastructure/. See also http://gcc.gnu.org/install/prerequisites.html for additional info. If you obtained GMP, MPFR and/or MPC from a vendor distribution package, make sure that you have installed both the libraries and the header files. They may be located in separate packages.

说是需要GMP 4.2+、MPFR 2.4.0+、MPC 0.8.0+。不知道是什么鬼。上次编译好像也有见到这个提示。

它叫我去翻看https://gcc.gnu.org/install/prerequisites.html,好咯。

Several support libraries are necessary to build GCC, some are required, others optional. While any sufficiently new version of required tools usually work, library requirements are generally stricter. Newer versions may work in some cases, but it's safer to use the exact versions documented. We appreciate bug reports about problems with newer versions, though. If your OS vendor provides packages for the support libraries then using those packages may be the simplest way to install the libraries.

GNU Multiple Precision Library (GMP) version 4.3.2 (or later)

MPFR Library version 2.4.2 (or later)

MPC Library version 0.8.1 (or later)

ISL Library version 0.15, 0.14, 0.13, or 0.12.2

看起来很复杂的样子,其实gcc自己给出了简单的解决办法,但是又不在这个页面写出来,这是傲娇吗=。=

方法就是,在gcc-4.9.3目录执行:

sh ./contrib/download_prerequisites

哗啦啦的就把各个依赖库下载好了。好棒。

坑2

回到objdir目录,再次执行:

~/download/gcc-4.9.3/configure --enable-languages=c,c++

出现一些warning:

configure: WARNING: using in-tree ISL, disabling version check

configure: WARNING: using in-tree CLooG, disabling version check

*** This configuration is not supported in the following subdirectories: gnattools target-libada target-libgfortran target-libgo target-libffi target-libbacktrace target-zlib target-libjava target-libobjc target-boehm-gc (Any other directories should still work fine.)

这些目录是什么东西,懒得了解了,只是warning的话先不管了。重点是还出现以下的error提示:

/usr/bin/ld: cannot find crt1.o: No such file or directory

/usr/bin/ld: cannot find crti.o: No such file or directory

/usr/bin/ld: skipping incompatible /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.9.3/libgcc.a when searching for -lgcc

/usr/bin/ld: cannot find -lgcc

/usr/bin/ld: cannot find -lgcc_s

/usr/bin/ld: cannot find -lc

/usr/bin/ld: skipping incompatible /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.9.3/libgcc.a when searching for -lgcc

/usr/bin/ld: cannot find -lgcc

/usr/bin/ld: cannot find -lgcc_s

/usr/bin/ld: cannot find crtn.o: No such file or directory

collect2: error: ld returned 1 exit status

configure: error: I suspect your system does not have 32-bit developement libraries (libc and headers). If you have them, rerun configure with --enable-multilib. If you do not have them, and want to build a 64-bit-only compiler, rerun configure with --disable-multilib.

这个意思应该是,我编译配置是默认支持32位和64位,但是32位的dev lib不齐全,建议我关掉32位。好咯。

~/download/gcc-4.9.3/configure --disable-multilib --enable-languages=c,c++

然后就天晴了,那些cannot find和error不见了(除了那个warning),没有其他异常提示:

configure: creating ./config.status

config.status: creating Makefile

开始编译

还是在objdir,执行:

make

经过漫长的等待,终于,出现了坑3。

坑3

make[3]: *** [s-attrtab] Killed

make[3]: Leaving directory `/root/download/gcc-4.9.3/objdir/gcc'

make[2]: *** [all-stage1-gcc] Error 2

make[2]: Leaving directory `/root/download/gcc-4.9.3/objdir'

make[1]: *** [stage1-bubble] Error 2

make[1]: Leaving directory `/root/download/gcc-4.9.3/objdir'

make: *** [all] Error 2

查了下,这个是因为我的vps内存不足导致的,看官们的机器应该不会出现这个错误T_T。

重启下vps再编译,看看能不能解决。

Oh,编译成功了。接着执行make install就完成了。

End。

(未经授权禁止转载)
Written on October 15, 2015

写作不易,您的支持是我写作的动力!