回归优快云 & 更换gcc版本 & 编译报错/usr/bin/ld: skipping incompatible解决

本文介绍了如何更换Linux系统中的GCC版本,并解决了在更换版本后遇到的编译错误问题。通过添加PPA源、安装指定版本的GCC以及设置软连接等步骤,最后通过安装对应的多库支持解决了编译器在链接阶段遇到的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本来已经打算不再使用优快云了,起因是因为优快云更换了一次主题之后不能恢复,用户吐槽了很久之后才换回来。因此感觉在第三方平台上写的内容不是真正属于自己的。现在习惯写博客用github pages+jekyll,个人wiki整理也从有道云笔记迁移到印象笔记,平时记录整理的需求基本满足了。但是每天还是会遇到很多坑,专门整理在笔记中感觉价值不大,不整理下来有点可惜了。因此尝试在优快云上记录每次遇到的报错以及解决方案,方便需要时回顾&分享。

最近有更换gcc版本的需求,并且在更换gcc版本之后遇到了一些错误。

更换gcc版本:

# 20180818 update optional:
# install add-apt-repository
sudo apt-get install software-properties-common -y

 首先添加ppa到库:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
# 安装gcc/g++
sudo apt-get install gcc-4.8 g++-4.8
sudo apt-get install gcc-4.9 g++-4.9
sudo apt-get install gcc-5 g++-5
sudo apt-get install gcc-6 g++-6
# 刷新db并locate
sudo updatedb && sudo ldconfig
locate gcc | grep -E "/usr/bin/gcc-[0-9]"
locate g++ | grep -E "/usr/bin/g\+\+-[0-9]"
# 输出:
/usr/bin/gcc-4.8
/usr/bin/gcc-4.9
/usr/bin/gcc-5
/usr/bin/gcc-6
/usr/bin/g++-4.8
/usr/bin/g++-4.9
/usr/bin/g++-5
/usr/bin/g++-6
# 手工更换gcc软连接
cd /usr/bin
sudo rm g++ gcc
sudo ln -s g++-5 g++
sudo ln -s gcc-5 gcc

更换gcc版本之后,编译一个程序遇到错误如下:

gcc-6   -fno-stack-protector  bof.c -m32 -o bof-6
输出:
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/6/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/6/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
collect2: error: ld returned 1 exit status

gcc编译时ld在链接时遇到了不合适的文件,因此需要安装对应的库文件。注意gcc-X-multilib中的X需要替换为你的gcc版本。

sudo apt-get install gcc-6-multilib

再编译就不会报错了。

/opt/android-ndk-r18b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --sysroot=/opt/android-ndk-r18b/platforms/android-21/arch-arm64 -I/home/chang/dev/mpp/mpp_build/install/usr/local/include -fPIC -c -o /tmp/ffconf.VYhSixhJ/test.o /tmp/ffconf.VYhSixhJ/test.c /opt/android-ndk-r18b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -L/home/chang/dev/mpp/mpp_build/install/usr/local/lib -lmpp --sysroot=/opt/android-ndk-r18b/platforms/android-21/arch-arm64 -o /tmp/ffconf.VYhSixhJ/test /tmp/ffconf.VYhSixhJ/test.o /..//bin/ld: cannot find crt1.o: No such file or directory /..//bin/ld: cannot find crti.o: No such file or directory /..//bin/ld: cannot find crtbegin.o: No such file or directory /..//bin/ld: cannot find -lmpp /..//bin/ld: cannot find -lgcc /..//bin/ld: cannot find -lgcc_s /..//bin/ld: skipping incompatible /opt/android-ndk-r18b/platforms/android-21/arch-arm64/usr/lib/libc.so when searching for -lc /..//bin/ld: skipping incompatible /opt/android-ndk-r18b/platforms/android-21/arch-arm64/usr/lib/libc.a when searching for -lc /..//bin/ld: skipping incompatible /opt/android-ndk-r18b/platforms/android-21/arch-arm64/usr/lib/libc.so when searching for -lc /..//bin/ld: skipping incompatible /opt/android-ndk-r18b/platforms/android-21/arch-arm64/usr/lib/libc.a when searching for -lc /..//bin/ld: cannot find -lc /..//bin/ld: cannot find -lgcc /..//bin/ld: cannot find -lgcc_s /..//bin/ld: cannot find crtend.o: No such file or directory /..//bin/ld: cannot find crtn.o: No such file or directory clang: error: linker command failed with exit code 1 (use -v to see invocation) C compiler test failed.好像更多错误了
最新发布
03-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值