Linux把gcc 4.4.7升级到4.8.x笔记

字号+ 编辑: 种花家 修订: 种花家 来源: 原创 2023-09-09 我要说两句(0)

不少插件需要gcc4.8+才能编译, 在CentOS6.x系统中升级gcc的一个实际笔记。

不像4.9.2, 升级4.8.5的gcc版本只需1GB的内存即可, 另外说一句, 4.9.2如果内存不够会中途报错, 通过调整swap大小来解决问题。


yum脚本自动安装

目前这个yum仓库可以安装三种高版本的gcc。


4.8安装

curl -Lks http://www.hop5.in/yum/el6/hop5.repo > /etc/yum.repos.d/hop5.repo
yum install gcc gcc-g++ -y
g++ --version


4.9安装

yum install centos-release-scl -y
yum install devtoolset-3-toolchain -y
scl enable devtoolset-3 bash
gcc --version
gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
g++ --version
g++ (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
gfortran --version
GNU Fortran (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)
Copyright (C) 2014 Free Software Foundation, Inc.
 
GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING


5.2安装

yum install centos-release-scl -y
yum install devtoolset-4-toolchain -y
scl enable devtoolset-4 bash
gcc --version
gcc (GCC) 5.2.1 20150902 (Red Hat 5.2.1-2)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
g++ --version
g++ (GCC) 5.2.1 20150902 (Red Hat 5.2.1-2)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


手动安装

获取GCC 4.8.5包(加拿大镜像):

wget http://gcc.skazkaforyou.com/releases/gcc-4.8.5/gcc-4.8.5.tar.gz

如果镜像挂了, 还有这两个镜像

wget http://mirrors-usa.go-parts.com/gcc/releases/gcc-4.8.5/gcc-4.8.5.tar.gz
wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-4.8.1/gcc-4.8.1.tar.bz2

解压缩:

tar -xf gcc-4.8.5.tar.gz

进入到目录gcc-4.8.5,

cd gcc-4.8.5

运行:

./contrib/download_prerequisites

这个脚本会帮我们下载、配置、安装依赖库。

建立输出目录并到目录里:

mkdir gcc-build-4.8.5
cd gcc-build-4.8.5
../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib

–enable-languages表示你要让你的gcc支持那些语言,-disable-multilib不生成编译为其他平台可执行代码的交叉编译器。-disable-checking生成的编译器在编译过程中不做额外检查,也可以使用-enable-checking=xxx来增加一些检查;

编译和安装, 等待时间较长:

make && make install

验证:

gcc -v

或者g++ -v,如果显示的gcc版本仍是以前的版本,就需要重启系统;或者可以查看gcc的安装位置:which gcc;然后在查看版本 /usr/local/bin/gcc -v,通常gcc都安装在该处位置。


问题解决

make报错

configure: error: C++ compiler missing or inoperational

需要安装编译器, yum安装命令为:

yum install gcc-c++

再make解决

阅完此文,您的感想如何?
  • 有用

    1

  • 没用

    0

  • 开心

    0

  • 愤怒

    0

  • 可怜

    0

1.如文章侵犯了您的版权,请发邮件通知本站,该文章将在24小时内删除;
2.本站标注原创的文章,转发时烦请注明来源;
3.交流群: PHP+JS聊天群

相关课文
  • Linux系统下word文档转成pdf的办法

  • ubuntu和debian安装nginx或者tengine报错, 找不到pcre依赖库的解决办法

  • linux终端下借助awk命令查询筛出网站access.log日志里的统计信息

  • 常见的web中间件请求返回状态码

我要说说
网上宾友点评
沙发已空