Centos 7/linux 安装gcc 教程 | 您所在的位置:网站首页 › 虚拟机安装编译器教程 › Centos 7/linux 安装gcc 教程 |
Centos 7/linux 安装gcc 的两种方式
一、直接安装gcc
操作环境 RHEL/Centos 6/7,在进行内核编译时编译器版本,需要升级gcc编译器,选择gcc-11.2.0。 http://ftp.gnu.org/gnu/gcc 里面提供所有的gcc版本供下载。 1、查看当前RHEL/Centos版本: [root@linuxprobe ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.0 (Maipo)2、查看现有的gcc版本: [root@linuxprobe ~]# gcc --version gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16) Copyright (C) 2013 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. [root@linuxprobe ~]# gcc --version3、安装RHEL/Centos7默认的开发工具,包含gcc,g++,make等等一系列工具: [root@linuxprobe ~]# yum groupinstall "Development Tools"4、查看默认动态库: [root@linuxprobe ~]# strings /usr/lib64/libstdc++.so.6 | grep GLIBC GLIBCXX_3.4 GLIBCXX_3.4.1 GLIBCXX_3.4.2 GLIBCXX_3.4.3 GLIBCXX_3.4.4 GLIBCXX_3.4.5 GLIBCXX_3.4.6 GLIBCXX_3.4.7 GLIBCXX_3.4.8 GLIBCXX_3.4.9 GLIBCXX_3.4.10 GLIBCXX_3.4.11 GLIBCXX_3.4.12 GLIBCXX_3.4.13 GLIBCXX_3.4.14 GLIBCXX_3.4.15 GLIBCXX_3.4.16 GLIBCXX_3.4.17 GLIBCXX_3.4.18 GLIBCXX_3.4.19 GLIBC_2.3 GLIBC_2.2.5 GLIBC_2.14 GLIBC_2.4 GLIBC_2.3.2 GLIBCXX_DEBUG_MESSAGE_LENGTH [root@linuxprobe ~]# strings /usr/lib64/libstdc++.so.6 | grep6、安装gcc的依赖软件,gcc的软件包内提供了自动下载需要软件的脚本./contrib/download_prerequisites ,这个神奇的脚本文件会帮我们下载、配置、安装依赖库,可以节约我们大量的时间和精力: [root@linuxprobe src]# cd gcc-7.3.0/ [root@linuxprobe gcc-7.3.0]# ./contrib/download_prerequisites7、生成Makefile文件: [root@linuxprobe gcc-7.3.0]# ./configure -enable-checking=release -enable-languages=c,c++ -disable-multilib //multilib 关闭多架构支持,可以支持arm,m68,mips,msp430,powerpc架构。8、编译gcc: [root@linuxprobe gcc-7.3.0]# make -j49、编译异常错误 configure: WARNING: using in-tree isl, disabling version check *** This configuration is not supported in the following subdirectories: gnattools gotools target-libada target-libhsail-rt target-libgfortran target-libbacktrace target-libgo target-libffi target-libobjc target-liboffloadmic (Any other directories should still work fine.)此警告网上暂未找到解决方案 影响未知 Dwarf Error: found dwarf version '5', this reader only handles version 2, 3 and 4 information原因:系统ld链接器版本过低,不支持 dwarf 5 解决方案:1、# export CFLAGS='-gdwarf-4 -gstrict-dwarf' make clean 重新配置 编译 指定dwarf 版本 2、安装Binutils 最新版 更新链接器 DWARF 第一版发布于 1992 年, 主要是为UNIX下的调试器提供必要的调试信息,例如PC地址对应的文件名及行号等信息,以方便源码级调试 其包含足够的信息以供调试器完成特定的一些功能, 例如显示当前栈帧(Stack Frame)下的局部变量, 尝试修改一些变量, 直接跳到函数末尾等 有足够的可扩展性,可为多种语言提供调试信息: 如: Ada, C, C++, Fortran, Java, Objective C, Go, Python, Haskell ... 除了编译/调试器外,还可用于从运行时地址还原源码对应的符号|行号的工具(如: atos)10、安装gcc: [root@linuxprobe gcc-7.3.0]# make install11、 查看最新动态库: [root@localhost ~]# strings /usr/lib64/libstdc++.so.6 | grep GLIBC 二、安装c++ 开发环境 devtoolset安装配置 SCL YUM 软件源 yum install centos-release-scl centos-release-scl-rh查看开发环境可用列表 yum search devtoolset --enablerepo='centos-sclo-rh'
所有用户长期生效 打开./root/.bashrc 文件尾写入 source scl_source enable devtoolset-11写入后source ./root/.bashrc 配置使用devtoolset-11 c++ 开发环境 打开etc/profile写入 export CPLUS_INCLUDE_PATH=/opt/rh/devtoolset-11/root/usr/include/c++/11:/opt/rh/devtoolset-11/root/usr/include/c++/11/x86_64-redhat-linux:/usr/include/ export C_INCLUDE_PATH=/opt/rh/devtoolset-11/root/usr/include/c++/11:/opt/rh/devtoolset-11/root/usr/include/c++/11/x86_64-redhat-linux:/usr/include/强烈推荐使用此种方式 引用: https://techglimpse.com/dwarf-error-found-dwarf-version-solution/ https://www.cnblogs.com/dinghailong128/p/12153330.html https://blog.csdn.net/qq_27525611/article/details/104626114 |
CopyRight 2018-2019 实验室设备网 版权所有 |