安裝到本地指定目錄复唤,先指定本地目錄為home目錄下的local陶缺。并導(dǎo)入到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
如果能聯(lián)網(wǎng)的話最后成功后是這樣的:
$ ./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.
如果不能聯(lián)網(wǎng),則需要自己手動下載到本地
ftp://gcc.gnu.org/pub/gcc/infrastructure/在這個網(wǎng)址中找到需要依賴的三個包塘匣,下載到本地先安裝這三個包
安裝第一個脓豪;是有順序的。
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的網(wǎng)址中下載
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安裝完成历谍,
繼續(xù)編譯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.
編譯報錯,根據(jù)提示辣垒,加上--disable-multilib
參數(shù)再編譯一次
./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
愁死人了
總結(jié)
當安裝到指定目錄時候,再沒有root權(quán)限的情況下印蔬,可以通過指定LDFLAGS和CPPFLAGS勋桶,將安裝的依賴包的lib和include路徑指定。就可以編譯成功了侥猬,