参考链接:
https://www.cnblogs.com/liutongqing/p/11277306.html
https://blog.csdn.net/enson16855/article/details/52205044
gcc
下载地址:
此处我们选择gcc-10.2.0
版本进行下载。
下载完成后。解压,配置,编译。
tar -vxf gcc-10.2.0.tar.xz
mkdir build
cd build/
../configure --prefix=/usr/local/gcc-10.2.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib
配置时报错:
configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+
解决该报错,请参考:
Error:Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+
gcc 配置命令:
../configure --prefix=/usr/local/gcc-10.2.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.5 --with-mpc=/usr/local/mpc-0.9
解决掉上述报错后。
使用 make && sudo make install
即可编译出高版本(gcc-10.2.0
)的gcc
。
adams@adams-pc:~$ gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/bin/../libexec/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper
目标:x86_64-pc-linux-gnu
配置为:../configure --prefix=/usr/local/gcc-4.7 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.0 --with-mpc=/usr/local/mpc-0.9
线程模型:posix
Supported LTO compression algorithms: zlib
gcc 版本 10.2.0 (GCC)
adams@adams-pc:~$
make 时间很长,很长,很长,本人编译了7个小时。所以有条件的话,在编译时,可以使用make -j8
如果想把高版本的gcc
安装到系统中,建议在configure
阶段,不要加上prefix
参数。
如果install
到自己指定的目录后,再想把编译出的文件( 二进制文件,库,头文件等)拷贝到系统目录下时,一定要拷贝完全:bin include lib lib64 libexec share
这几个目录要拷贝到对应的目录。
不然有可能会报错:
C compiler cannot create executables