linux下GCC安装

安装到本地指定目录,先指定本地目录为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路径指定。就可以编译成功了,

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 202,529评论 5 475
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,015评论 2 379
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,409评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,385评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,387评论 5 364
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,466评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,880评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,528评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,727评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,528评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,602评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,302评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,873评论 3 306
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,890评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,132评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,777评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,310评论 2 342

推荐阅读更多精彩内容