centos7 老的gcc升级

1.

由于centos7.4初始gcc版本为4.8.5

echo 'source /opt/rh/devtoolset-7/enable' >> ~/.bashrc

source ~/.bashrc

保存到配置文件电脑再次启动的时候依然有效

[root@localhost linux-2.6.0]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-7/root/usr --mandir=/opt/rh/devtoolset-7/root/usr/share/man --infodir=/opt/rh/devtoolset-7/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --with-default-libstdcxx-abi=gcc4-compatible --with-isl=/builddir/build/BUILD/gcc-7.3.1-20180303/obj-x86_64-redhat-linux/isl-install --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC)

参考1

Linux内核学习(包含Linux 2.6内核编译安装流程)-优快云博客

参考2

Centos7 一次搞定:配置yum,解决scl问题,安装升级c++11,ssh连接vscode_centos-release-scl-优快云博客

编译  linux内核的时候出现的问题

### 升级 GCC 的方法 在 CentOS 7 上默认安装的 GCC 版本可能较低,为了满足开发需求或兼容某些软件包的要求,有时需要升级到更高版本的 GCC。以下是详细的步骤说明: #### 使用 Devtoolset 安装高版本 GCC DevToolset 是 Red Hat 提供的一套工具集,允许开发者在同一台机器上拥有多个编译器版本并轻松切换。 1. 配置额外仓库以便获取最新版 GCC 工具链: ```bash sudo yum install centos-release-scl ``` 2. 安装所需的具体版本的 devtoolset (这里以 devtoolset-9为例): ```bash sudo yum install devtoolset-9 ``` 3. 启用新安装的 toolset 并验证其是否生效: ```bash scl enable devtoolset-9 bash gcc --version ``` 通过上述命令启用后,在当前 shell 中使用的将是来自 devtoolset-9 的 GCC 编译器及其关联库文件[^1]。 #### 手动编译安装 GCC 如果希望永久替换系统的默认 GCC 或者需要特定配置选项,则可以选择手动下载源码进行编译安装: 1. 下载目标版本的 GCC 源代码压缩包; 2. 解压 tarball 文件并将解压后的目录作为工作区; 3. 创建一个新的构建目录用于放置生成的目标文件而不是污染原始源树; 4. 进入创建好的 build 目录执行如下配置脚本(假设要安装至 `/usr/local/gcc` 路径下),注意调整 `--prefix` 参数指向期望位置: ```bash ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib --prefix=/usr/local/gcc ``` 5. 开始编译过程,这一步可能会花费较长时间取决于计算机性能; ```bash make -j$(nproc) ``` 6. 将编译完成的结果复制到指定路径内: ```bash sudo make install ``` 7. 更新环境变量 PATH 来优先选用新的 GCC 可执行程序: ```bash export PATH="/usr/local/gcc/bin:$PATH" ``` 8. 添加以上导出语句到 `.bashrc` 或其他启动脚本中实现持久化设置. 请注意这种方式会覆盖系统自带的基础组件,因此建议仅当确实有必要时才采取此方案,并确保了解潜在风险以及具备解决问题的能力[^2].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值