记录
下载
wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.gz
解压 下载依赖
tar zxf gcc-4.8.5.tar.gz
cd gcc-4.8.5
./contrib/download_prerequisites
在gcc的同级 新建目录
cd ..
mkdir gcc-build
编译安装
cd gcc-build
../gcc-4.8.4/configure --prefix=/home/username/.local/ --enable-checking=release --enable-languages=c,c++ --disable-multilib
make -j4
make install
编译出错 接下来开始修改源码
1
cfns.gperf:101:1: error: 'const char* libc_name_p(const char*, unsigned int)' redeclared inline
参考网址
修改源码
cd ~/gcc-4.8.2/gcc/cp
vim Make-lang.in
# 然后参考网址修改 +表示新增 -表示删除
# 修改完保存退出 继续下一个文件
vim cfns.gperf
vim cfns.h
vim except.c
然后编译 出现以下错误
2
In file included from ../../../../libgcc/unwind-dw2.c:405:0:
./md-unwind-support.h: In function ‘x86_fallback_frame_state’:
./md-unwind-support.h:141:18: error: field ‘uc’ has incomplete type
struct ucontext uc;
cd ./x86_64-unknown-linux-gnu/libgcc/
vim md-unwind-support.h
在vim命令模式输入:61
可直接定位到61行
在61行和141行将struct ucontext改成struct ucontext_t即可
3
version `CXXABI_1.3.8` not found (required by /usr/lib/x86_64-linux-gnu/libicuuc.so.60)
cd ./x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/
rm -rf libstdc++.so.6
ln -snf /usr/lib/x86_64-linux-gnu/libstdc++.so.60 ./libstdc++.so.6
然后编译出现同样的错
继续修改
cd ./x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/
rm -rf libstdc++.so.6
ln -snf /usr/lib/x86_64-linux-gnu/libstdc++.so.6 ./libstdc++.so.6
这里非常奇怪 链接libstdc++.so.6
有时会出错
链接libstdc++.so.60
有时也会出错
我是经过一轮修改链接莫名其妙成功了
4
../../../../gcc-4.8.2/libsanitizer/asan/asan_linux.cc: In function 'bool
__asan::AsanInterceptsSignal(int)':
../../../../gcc-4.8.2/libsanitizer/asan/asan_linux.cc:95:20: error: 'SIGSEGV'
was not declared in this scope
return signum == SIGSEGV && flags()->handle_segv;
cd ../gcc-4.8.2/libsanitizer/asan
vim asan_linux.cc
添加头文件#include <signal.h>
这里顺便解决第5个错误
vim ../tsan/tsan_platform_linux.cc
将 __res_state *statp = (__res_state*)state;
修改为struct __res_state *statp = (struct __res_state*)state;
然后就是略微漫长的编译
make -j4
编译成功
make install
然后环境变量
vim ~/.bashrc
添加内容
export PATH="$HOME/.local/bin:$PATH"
保存退出
source ~/.bashrc
gcc --version
即可显示为对应版本
先做个记录
有空再补充
主要 !> 参考
其中涉及修改源码等操作
其他教程都会出错 需要修改源码才能编译成功
其中 链接libstdc++.so.6 这一步
在编译过程中
首次链接后编译还是出错
然后链接出错提示的文件
还是出错
这时候 再次链接libstdc++.so.6 编译成功!!!
查看usr/lib64/libstdc++.so.6
cd /usr/
这是若发现不存在lib64
目录
则查看lib/x86_64-linux-gnu
要链接的文件就在此目录下
/usr/bin/ld: cannot find crt1.o: No such file or directory
若编译过程中出现/usr/bin/ld: cannot find crt1.o: No such file or directory
错误
则应该是./configure
时没有指定参数--disable-multilib
加入参数后重新./configure
生成编译文件
编译通过