ubuntu 20.04安装GCC G++ 6.2,支持c++ 14

  1. 下载源码包
    wget http://ftp.gnu.org/gnu/gcc/gcc-6.2.0/gcc-6.2.0.tar.bz2
  2. 解压
    tar jxf gcc-6.2.0.tar.bz2
  3. 下载编译依赖
    cd gcc-6.2.0
    ./contrib/download_prerequisites
  4. 生成makefile文件
    mkdir gcc-build-6.2.0
    cd gcc-build-6.2.0/
    ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
  5. 编译
    make -j4
    4表示使用4个核心,根据你的CPU来指定。也可不指定任何参数
  6. 安装
    make install
  7. 验证
    gcc -v
    编译过程中遇到的问题:

问题1:error: dereferencing pointer to incomplete type 'struct ucontext'
在函数'x86_64_fallback_frame_state'中: ./md-unwind-support.h:65:47: 错误: dereferencing pointer to incomplete type 'struct ucontext'
sc = (struct sigcontext *) (void *) &uc_->uc_mcontext;

解决方案:
struct ucontext * uc_ = context->cfa;
修改为
struct ucontext_t * uc_ = context->cfa;
重新编译make


问题2:sanitizer_platform_limits_posix.cc:158:23: 致命错误:sys/ustat.h:没有那个文件或目录
../../.././libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc:159:
28: fatal error: sys/ustat.h: No such file or directory
#include <sys/ustat.h>
^
compilation terminated.

解决方案:
修改libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc文件:
vim libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
首先注释掉 #include <sys/ustat.h>
接着在 251 行修改 unsigned struct_ustat_sz = sizeof(struct ustat); 语句
注释掉251行,换行后粘贴以下内容:
// Use pre-computed size of struct ustat to avoid <sys/ustat.h> which
// has been removed from glibc 2.28.
#if defined(aarch64) || defined(s390x) || defined (__mips64) \
|| defined(powerpc64) || defined(arch64) || defined(__sparcv9) \
|| defined(x86_64)
#define SIZEOF_STRUCT_USTAT 32
#elif defined(arm) || defined(i386) || defined(mips) \
|| defined(powerpc) || defined(s390)
#define SIZEOF_STRUCT_USTAT 20
#else
#error Unknown size of struct ustat
#endif
unsigned struct_ustat_sz = SIZEOF_STRUCT_USTAT;
重新make


问题3:
../../.././libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc:270:22: 错误: 聚
合'sigaltstack handler_stack'类型不完全,无法被定义
struct sigaltstack handler_stack;
^~~~~~~~~~~~~
解决方案:

1.打开libsanitizer/sanitizer_common/sanitizer_linux.h文件,注释第22行的struct sigaltstack;
2.修改31.32行:
uptr internal_sigaltstack(const struct sigaltstack* ss,
struct sigaltstack* oss);

修改为
uptr internal_sigaltstack(const void* ss, void* oss);

3.修改libsanitizer/sanitizer_common/sanitizer_linux.cc文件549、550行
uptr internal_sigaltstack(const struct sigaltstack *ss,
struct sigaltstack *oss) {

修改为
uptr internal_sigaltstack(const void *ss, void *oss) {

4.修改libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc270行
struct sigaltstack handler_stack;
修改为
stack_t handler_stack;

5.修改libsanitizer/tsan/tsan_platform_linux.cc294行
__res_state *statp = (__res_state*)state;
修改为
struct __res_state *statp = (struct __res_state*)state;
重新make


问题4:sanitizer_common/sanitizer_internal_defs.h:254:72: error: size of array 'assertion_failed__1142' is negative
解决方案:
修改 /gcc-6.3.0/configure文件
删除文件中 target-libsanitizer \,大概在两千多行
重新make

相关推荐
Better Bench9 小时前
ubuntu20.04安全的安装可穿墙的远程软件parsec
安全·ubuntu·远程·parsec
新手村领路人9 小时前
Ubuntu18.04 libc.so.6: version `GLIBC_2.28‘ not found问题
linux·ubuntu·pycharm
奥尔特星云大使12 小时前
详细的Linux系统更新yum源的教程
linux·运维·服务器·ubuntu·centos·yum源·epel源
lht63193561212 小时前
Ubuntu Server 系统安装图形界面
linux·运维·ubuntu
christine-rr12 小时前
linux常用命令(6)——网络管理
linux·服务器·网络·ubuntu·网络安全
~黄夫人~16 小时前
Ubuntu系统快速上手命令(详细)
linux·运维·笔记·ubuntu·postgresql
发光的沙子16 小时前
FPGA----petalinux的Ubuntu文件系统移植
linux·运维·ubuntu
lili-felicity16 小时前
解决VMware Workstation Pro 17中Ubuntu 24.04无法复制粘贴
linux·运维·ubuntu
BothSavage17 小时前
Ubuntu-8卡H20服务器升级nvidia驱动+cuda版本
linux·服务器·ubuntu·gpu·nvidia·cuda·nvcc
本贾尼20 小时前
Linux系统下的终端,会话,shell,bash,进程组这几个概念的关系。
linux·服务器·网络·ubuntu·bash