linux下GCC安装

作者: 11的雾 | 来源:发表于2018-09-04 11:51 被阅读94次

    安装到本地指定目录,先指定本地目录为home目录下的local。并导入到path中
    export LOCAL_LIBS=$HOME/local/
    mkdir $LOCAL_LIBS
    export PATH=$LOCAL_LIBS/bin:$LOCAL_LIBS/usr/local/bin/:$PATH

    开始下载gcc后解压
    下载地址:https://gcc.gnu.org/
    tar -zxvf gcc-8.2.0.tar.gz
    ./configure --prefix=$LOCAL_LIBS
    编译后报错

    configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
    

    需要依赖 mpc,mpfr,gmp包,
    GCC 源码里自带脚本可以轻松下载依赖包。
    ./contrib/download_prerequisites
    如果能联网的话最后成功后是这样的:
    $ ./contrib/download_prerequisites
    gmp-6.1.0.tar.bz2: OK
    mpfr-3.1.4.tar.bz2: OK
    mpc-1.0.3.tar.gz: OK
    isl-0.18.tar.bz2: OK
    All prerequisites downloaded successfully.

    如果不能联网,则需要自己手动下载到本地
    ftp://gcc.gnu.org/pub/gcc/infrastructure/在这个网址中找到需要依赖的三个包,下载到本地先安装这三个包
    安装第一个;是有顺序的。

    tar jxvf gmp-6.1.0.tar.bz2
    ./configure --prefix=$LOCAL_LIBS
    make
    make install
    

    安装成功,这里先把安装成功后的部分信息粘贴在这里,

    Libraries have been installed in:
       /BIGDATA1/cygene_sydu_1/local/lib
    
    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the '-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the 'LD_RUN_PATH' environment variable
         during linking
       - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to '/etc/ld.so.conf'
    
    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and ld.so(8) manual pages.
    ----------------------------------------------------------------------
     /bin/mkdir -p '/BIGDATA1/cygene_sydu_1/local/include'
     /usr/bin/install -c -m 644 gmp.h '/BIGDATA1/cygene_sydu_1/local/include'
    make  install-data-hook
    make[4]: Entering directory `/BIGDATA1/cygene_sydu_1/software/gmp-6.1.0'
    
    +-------------------------------------------------------------+
    | CAUTION:                                                    |
    |                                                             |
    | If you have not already run "make check", then we strongly  |
    | recommend you do so.                                        |
    |                                                             |
    | GMP has been carefully tested by its authors, but compilers |
    | are all too often released with serious bugs.  GMP tends to |
    | explore interesting corners in compilers and has hit bugs   |
    | on quite a few occasions.                                   |
    |                                                             |
    +-------------------------------------------------------------+
    
    make[4]: Leaving directory `/BIGDATA1/cygene_sydu_1/software/gmp-6.1.0'
    make[3]: Leaving directory `/BIGDATA1/cygene_sydu_1/software/gmp-6.1.0'
    make[2]: Leaving directory `/BIGDATA1/cygene_sydu_1/software/gmp-6.1.0'
    make[1]: Leaving directory `/BIGDATA1/cygene_sydu_1/software/gmp-6.1.0'
    

    第二个

    tar  jxvf mpfr-3.1.4.tar.bz2
    cd mpfr-3.1.4
    ./configure --prefix=$LOCAL_LIBS
    make 
    make install
    

    安装成功后会有:

    Libraries have been installed in:
       /BIGDATA1/cygene_sydu_1/local/lib
    
    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the '-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the 'LD_RUN_PATH' environment variable
         during linking
       - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to '/etc/ld.so.conf'
    

    安装第三个:

    tar zxvf mpc-1.0.3.tar.gz
    cd mpc-1.0.3
    ./configure --prefix=$LOCAL_LIBS  LDFLAGS="-L/BIGDATA1/cygene_sydu_1/local/lib" CPPFLAGS="-I/BIGDATA1/cygene_sydu_1/local/include"
    make
    make install
    

    然后安装gcc

    cd gcc-8.2.0
    ./configure --prefix=$LOCAL_LIBS  LDFLAGS="-L/BIGDATA1/cygene_sydu_1/local/lib" CPPFLAGS="-I/BIGDATA1/cygene_sydu_1/local/include"
    

    安装报错:
    required isl version is 0.15 or later
    下载安装isl,还是在刚才下载mpc的网址中下载

    tar jxvf isl-0.18.tar.bz2
    cd isl-0.18
    ./configure --prefix=$LOCAL_LIBS  LDFLAGS="-L/BIGDATA1/cygene_sydu_1/local/lib" CPPFLAGS="-I/BIGDATA1/cygene_sydu_1/local/include"
    make
    make install
    

    没有报错,isl安装完成,
    继续编译gcc:

    ./configure --prefix=$LOCAL_LIBS  LDFLAGS="-L/BIGDATA1/cygene_sydu_1/local/lib" CPPFLAGS="-I/BIGDATA1/cygene_sydu_1/local/include"
    ···
    checking for isl 0.15 or later... yes
    The following languages will be built: c,c++,fortran,lto,objc
    *** This configuration is not supported in the following subdirectories:
         gnattools gotools target-libada target-libhsail-rt target-libgo target-libffi target-liboffloadmic
        (Any other directories should still work fine.)
    checking for default BUILD_CONFIG... bootstrap-debug
    checking for --enable-vtable-verify... no
    /usr/bin/ld: crt1.o: No such file: No such file or directory
    collect2: ld returned 1 exit status
    configure: error: I suspect your system does not have 32-bit development 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.
    

    编译报错,根据提示,加上--disable-multilib参数再编译一次

    ./configure --prefix=$LOCAL_LIBS  LDFLAGS="-L/BIGDATA1/cygene_sydu_1/local/lib" CPPFLAGS="-I/BIGDATA1/cygene_sydu_1/local/include" --disable-multilib
    make
    

    make报错了

    In file included from ../.././gcc/c/c-decl.c:53:
    ../.././gcc/builtins.h:23:17: warning: mpc.h: No such file or directory
    In file included from ../.././gcc/c/c-decl.c:53:
    ../.././gcc/builtins.h:87: error: expected ‘,’ or ‘...’ before ‘(’ token
    make[3]: *** [c/c-decl.o] Error 1
    make[3]: Leaving directory `/BIGDATA1/cygene_sydu_1/software/gcc-8.2.0/host-x86_64-pc-linux-gnu/gcc'
    make[2]: *** [all-stage1-gcc] Error 2
    make[2]: Leaving directory `/BIGDATA1/cygene_sydu_1/software/gcc-8.2.0'
    make[1]: *** [stage1-bubble] Error 2
    make[1]: Leaving directory `/BIGDATA1/cygene_sydu_1/software/gcc-8.2.0'
    make: *** [all] Error 2
    

    愁死人了

    总结

    当安装到指定目录时候,再没有root权限的情况下,可以通过指定LDFLAGS和CPPFLAGS,将安装的依赖包的lib和include路径指定。就可以编译成功了,

    相关文章

      网友评论

        本文标题:linux下GCC安装

        本文链接:https://www.haomeiwen.com/subject/lnfgwftx.html