from:http://blog.csdn.net/logicouter/article/details/7776507
下载依赖库:
GNU Multiple Precision Library (GMP) version 4.3.2 (or later)
Necessary to build GCC. If a GMP source distribution is found in a subdirectory of your GCC sources named gmp, it will be built together with GCC. Alternatively, if GMP is already installed but it is not in your library search path, you will have to configure with the --with-gmp configure option. See also --with-gmp-lib and --with-gmp-include.
MPFR Library version 2.4.2 (or later)
Necessary to build GCC. It can be downloaded from http://www.mpfr.org/. If an MPFR source distribution is found in a subdirectory of your GCC sources named mpfr, it will be built together with GCC. Alternatively, if MPFR is already installed but it is not in your default library search path, the --with-mpfr configure option should be used. See also --with-mpfr-lib and --with-mpfr-include.
MPC Library version 0.8.1 (or later)
Necessary to build GCC. It can be downloaded from http://www.multiprecision.org/. If an MPC source distribution is found in a subdirectory of your GCC sources named mpc, it will be built together with GCC. Alternatively, if MPC is already installed but it is not in your default library search path, the --with-mpc configure option should be used. See also --with-mpc-lib and --with-mpc-include.
在ftp://gcc.gnu.org/pub/gcc/infrastructure下载并按上述顺序编译。
设置环境变量LD_LIBRARY_PATH,包含上述3个库下的lib目录(重要!)否则会出现如cannot comput subfix(.o)等问题。
../gcc-4.7.1/configure --prefix=/home/changweiwu/usr --with-gmp=/home/changweiwu/usr/ --with-mpfr=/home/changweiwu/usr --with-mpc=/home/changweiwu/usr/ --enable-languages=c,c++
以上在suse的机器上编译通过,但在ubuntu下会有下述问题,需要进行设置头文件、库文件搜索路径:
ISSUE#1
checking for suitable m4... configure: error: No usable m4 in $PATH or /usr/5bin (see config.log for reasons).
Solution:
#sudo apt-get install m4
ISSUE#2
In file included from /usr/include/stdio.h:28:0,
from ../../../../gcc-4.7.0/libgcc/../gcc/tsystem.h:88,
from ../../../../gcc-4.7.0/libgcc/libgcc2.c:29:
/usr/include/features.h:324:26: fatal error: bits/predefs.h: No such file or directory
compilation terminated.
make[5]: *** [_muldi3.o] Error 1
Analysis:
Use 'locate bits/predefs.h' to find the path of this header. (in '/usr/include/x86_64-linux-gnu')
Solution:
#export C_INCLUDE_PATH=/usr/include/i386-linux-gnu && export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH
ISSUE#3
In file included from /usr/include/features.h:389:0,
from /usr/include/stdio.h:28,
from ../../../../gcc-4.7.0/libgcc/../gcc/tsystem.h:88,
from ../../../../gcc-4.7.0/libgcc/libgcov.c:29:
/usr/include/i386-linux-gnu/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory
compilation terminated.
make[5]: *** [_gcov.o] Error 1
Analysis:
Related to libc multilib, disable it with '--disable-multilib' should work.
Solution:
add '--disable-multilib' and 'configure' again, then run 'make'.
ISSUE#4
/usr/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status
make[3]: *** [libgcc_s.so] Error 1
make[3]: *** Waiting for unfinished jobs....
Analysis:
Use 'locate crti.o' to find this file. (in '/usr/lib/i386-linux-gnu/crti.o') Set LIBRARY_PATH (LDFLAGS)
Solution:
#export LIBRARY_PATH=/usr/lib/i386-linux-gnu
make && make install
参考资料:
http://gcc.gnu.org/install/
http://gcc.gnu.org/onlinedocs/gccint/index.html
http://hi.baidu.com/yehsos/blog/item/88b2d6b4200dcb748ad4b2d5.html
http://www.oschina.net/question/12_49423
http://blog.csdn.net/gengshenghong/article/details/7498085