gcc 4.7.1编译小结 bits/predefs.h等错误

来源:互联网 发布:胡家窝棚数据分析 编辑:程序博客网 时间:2024/06/04 00:06

最近想用gcc来dump一些信息出来,比如说文件依赖关系,ast。google了一下,有两种方法:hack跟plugin。codeviz是通过修改gcc3.4.6来dump出函数调用关系,而VCG是gcc的一个插件,用来可以用来分析控制流图,函数调用图等诸多信息。但gcc是到4.5之后才支持plugin的机制,我机器版本太低,下了gcc4.7.1(各版本的地址http://ftp.gnu.org/gnu/gcc/),根据官方建议,新建一个目录用于编译,因gcc的make里面,没有clean,不过对我们编译其他开源项目同样有用:ls的时候比较干净:)。

下载依赖库:

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://blog.csdn.net/logicouter/article/details/7776507

原创粉丝点击