官网地址:GCC, the GNU Compiler Collection- GNU Project
下载编译
wget http://mirror.linux-ia64.org/gnu/gcc/releases/gcc-10.1.0/gcc-10.1.0.tar.gztar zxvf gcc-10.1.0.tar.gzcd gcc-10.1.0/mkdir buildcd build/../configure
报错,提示信息configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specifytheir locations. Source code for these libraries can be found attheir respective hosting sites as well as athttps://gcc.gnu.org/pub/gcc/infrastructure/. See alsohttp://gcc.gnu.org/install/prerequisites.html for additional info. Ifyou obtained GMP, MPFR and/or MPC from a vendor distribution package,make sure that you have installed both the libraries and the headerfiles. They may be located in separate packages.
vi ../contrib/download_prerequisites
修改镜像服务器地址
base_url='http://mirror.linux-ia64.org/gnu/gcc/infrastructure/'
接下来下载需要的文件
cd ../
bash contrib/download_prerequisites
可能运行较慢,看不到就着急啊……来,手动下载吧(文件名在contrib/download_prerequisites 里面有)
wget http://mirror.linux-ia64.org/gnu/gcc/infrastructure/gmp-6.1.0.tar.bz2wget http://mirror.linux-ia64.org/gnu/gcc/infrastructure/mpfr-3.1.4.tar.bz2wget http://mirror.linux-ia64.org/gnu/gcc/infrastructure/mpc-1.0.3.tar.gz#wget http://mirror.linux-ia64.org/gnu/gcc/infrastructure/isl-0.18.tar.bz2tar jxvf gmp-6.1.0.tar.bz2tar jxvf mpfr-3.1.4.tar.bz2tar zxvf mpc-1.0.3.tar.gz#tar jxvf isl-0.18.tar.bz2ln -s gmp-6.1.0 gmpln -s mpfr-3.1.4 mpfrln -s mpc-1.0.3 mpc
再次
cd build/
../configure
如果报错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.
也就是说,configure推断本机没有32位开发库,如果的确有就加上--enable-multilib选项,否则就使用--disable-multilib选项只构建64位版本。
就改为
../configure --disable-multilib
生成Makefile后执行(-j 8代表8个线程)
make -j 8
……需要等待好久,吃个饭去吧
安装
sudo make install
安装完成后看下版本
gcc --version
g++ --version
都是10.1.0了
使用问题
/usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by ./bin/navicat-patcher)
解决
#首先找下新编译的这个文件在哪里
find /usr/local -name "libstdc++.so.6"
#输出/usr/local/lib64/libstdc++.so.6
#旧版文件备份
sudo mv /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.bak
#创建软连接过去
sudo ln -s /usr/local/lib64/libstdc++.so.6 /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#确认下GLIBCXX_3.4.26在不在输出清单里
strings /usr/local/lib64/libstdc++.so.6 | grep GLIBC