原因:
XXXX待补充
1.查看当前gcc版本
gcc --version
2.下载依赖包
直接安装gcc的话会提示在安装gcc之前,必须安装GMP 4.2以上版本,MPFR2.3.1以上版本, MPC 0.8.0以上版本。
四个包下载的话可能比较慢,我放在了网盘里
链接: https://pan.baidu.com/s/1ZcDDbbRWqpNHbQ9sjyzViA
提取码: 1234
3.下载后解压
tar -xvzf xxx.tar.gz
tar -xvjf xxx.tar.bz2
4.编译顺序
📢:gmp -> mpfr -> mpc ->gcc
4.1 编译安装gmp
cd /tmp/gmp-4.3.2
mkdir build && cd build
../configure --prefix=/opt/compiler/gcc-4.8.2
make -j20
make install
在make后可能会出现问题:
make: *** No targets specified and no makefile found. Stop.
yum install m4
我这里是安装了一下m4才出现了makefile文件,可以参考一下
4.2 编译安装mpfr
cd /tmp/mpfr-2.4.2
mkdir build && cd build
../configure --prefix=/opt/compiler/gcc-4.8.2 --with-gmp=/opt/compiler/gcc-4.8.2
make -j20
make install
4.3 编译安装mpc
cd /tmp/mpc-0.8.1
mkdir build && cd build
../configure --prefix=/opt/compiler/gcc-4.8.2 --with-gmp=/opt/compiler/gcc-4.8.2 --with-mpfr=/opt/compiler/gcc-4.8.2
make -j20
make install
4.4 编译安装gcc
主要配置选项说明如下:
—prefix # 设置工具链安装路径
—disable-multilib # 关闭跨平台支持
—enable-languages # 可设置下列选项的一个或几个“all, ada, c, c++, fortran, go, jit, lto, objc, obj-c++”,默认不设置与all等效。
详细配置选项参考:https://gcc.gnu.org/install/configure.html
export LD_LIBRARY_PATH=/opt/compiler/gcc-4.8.2/lib/:$LD_LIBRARY_PATH
cd /tmp/gcc-4.8.2
mkdir build && cd build
../configure --prefix=/opt/compiler/gcc-4.8.2 --with-gmp=/opt/compiler/gcc-4.8.2 --with-mpc=/opt/compiler/gcc-4.8.2 --with-mpfr=/opt/compiler/gcc-4.8.2 --enable-checking=release --enable-ld=yes --enable-gold=yes --disable-multilib
make -j20
make install
在这里可能会出错
尝试安装
yum install gcc-c++
不过还是出问题:
这哥们把我的问题都出现了:
参考网址:https://blog.csdn.net/refuil/article/details/51479431
sudo gedit config.log # 查看日志,搜索"error"
问题1:
issue: configure: error: C++ compiler missing or inoperational
解释:没有C++编译器
yum install gcc-c++
问题2:
issue: conftest.cpp:11:2: error: #error -static-libstdc++ not implemented
解释:没有C,C++静态库
yum install glibc-static libstdc+±static -y
我主要是安装了
yum install libstdc++-static
'问题3:
但报"No package libstdc+±static available",即没有-static-libstdc++源,问题仍存在。
"checking whether g++ accepts -static-libstdc++ -static-libgcc"时报出的,可忽略。
issue: conftest.c:10:25: error: isl/version.h: No such file or directory
解释:没有ISL
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.12.2.tar.bz2
但是ftp连接不上,找到了等价官网下载地址:
https://sourceforge.net/projects/libisl/files/isl-0.12.2.tar.bz2/download
这里跟之前安装依赖库一样,编译安装即可
tar jxvf isl-0.12.2.tar.bz2
cd isl-0.12.2; ./configure
make; make install
cd ..
不过我变异过程中又出错,导致没有makefile文件
问题4:
checking gmp.h usability… no
checking gmp.h presence… no
checking for gmp.h… no
configure: error: Header file gmp.h not found; maybe use --with-gmp-include=INCLUDE_PATH
ERROR: configuration failed for package ‘gmp’`
解释:大概意思就是缺少gmp.h,编译失败
参考:https://stackoverflow.com/questions/74375271/r-gmp-package-installation-fails-configure-error-header-file-gmp-h-not-found
解决:
yum install gmp-devel
或者(我用的第一个,第二个lib查找不到)
apt-get install libgmp-dev
然后重新编译安装应该就没问题了
configure: current value:
-static-libstdc++ -static-libgcc ' configure: error: in
/ssd2/work/xxxx/gcc-4.8.2/build/intl’:
configure: error: changes in the environment can compromise the build
configure: error: runmake distclean' and/or
rm ./config.cache’ and start over
make[2]: *** [configure-stage1-intl] Error 1
make[2]: Leaving directory/ssd2/work/xxxxx/gcc-4.8.2/build' make[1]: *** [stage1-bubble] Error 2 make[1]: Leaving directory
/ssd2/work/xxxx/gcc-4.8.2/build’
make: *** [all] Error 2
貌似是多次编译有点冲突了,运行
rm ./config.cache
或者
make distclean
然后重新编译,接着出错:
问题5:
issue:
./conftest: errorwhile loading sharedlibraries: libisl.so.10:cannot open shared objectfile: No such file or directory
但是这个文件在"/usr/local/lib"目录下是存在的,只是找不到
两种方法:
1.vi /etc/ld.so.conf
原始文件应该是这样的:
include ld.so.conf.d/*.conf
添加"/usr/local/lib"->改成:
include ld.so.conf.d/*.conf
/usr/local/lib
然后运行重建命令
ldconfig
重建后出现:
ldconfig: /usr/local/lib/libisl.so.10.2.2-gdb.py is not an ELF file - it has the wrong magic bytes at the start.
可以忽略
查看是否写入了缓存文件
strings /etc/ld.so.cache |grep libisl
接着
./configure
make
make install
2.方法我没看,但是也是可行的
参考这个blog通过在bashrc里面添加环境变量
https://blog.csdn.net/youth_xin/article/details/133908956
问题6:
conftest.c:10:27:error: cloog/version.h: No such file ordirectory
解释:没有CLooG
地址还是放在这里,可以直接wget
https://gcc.gnu.org/pub/gcc/infrastructure/cloog-0.18.1.tar.gz
tar zxvf cloog-0.18.1.tar.gz
cd cloog-0.18.1; ./configure
make; make install
可以再运行一下
ldconfig
以防他找不到。
返回gcc中的build目录,先执行
make distclean
接着编译,make
目前出错:应该是最后一个错误
gcc: error: unrecognized command line option ‘-V’
gcc: fatal error: no input files
gcc: error: unrecognized command line option ‘-qversion’
gcc: fatal error: no input files
g++: error: unrecognized command line option ‘-V’
g++: fatal error: no input files
g++: error: unrecognized command line option ‘-qversion’
g++: fatal error: no input files
conftest.c:15:5: error: unknown type name 'choke'
stage2_werror_flag=‘’
暂时还不知道怎么解决
后续等我随后补充~
参考内容:
https://blog.csdn.net/qq_28168421/article/details/106221718
https://blog.51cto.com/u_11736068/1915587
https://blog.csdn.net/u010552731/article/details/90031697
https://blog.csdn.net/refuil/article/details/51479431
https://stackoverflow.com/questions/74375271/r-gmp-package-installation-fails-configure-error-header-file-gmp-h-not-found
https://www.cnblogs.com/MMingzhao/p/10285396.html