1. 程式人生 > >gcc 4.7.1編譯小結 bits/predefs.h等錯誤

gcc 4.7.1編譯小結 bits/predefs.h等錯誤

最近想用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