ubuntu 20.04安裝GCC G++ 6.2,支援c++ 14

VictorYu發表於2024-09-09

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

相關文章