编译过程中报错 /usr/bin/ld: cannot find -lstdc++: No such file or directory 解决

文章讲述了在Ubuntu22.04WSL环境下,使用cmake编译开源项目时遇到libstdc++找不到的错误,问题源于系统中安装了多个gcc版本,特别是gcc-11和gcc-12的冲突。解决方法是卸载不必要的版本并安装g++-12。
摘要由CSDN通过智能技术生成

WSL-Ubuntu 22.04 中编译某大型开源项目,用到 cmake,过程中报错 /usr/bin/ld: cannot find -lstdc++: No such file or directory
但实际上系统中有这个库文件,使用 ldconfig -p | grep libstdc++ 命令输出为

libstdc++.so.6 (libc6,x86-64) => /lib/x86_64-linux-gnu/libstdc++.so.6
libstdc++.so.6 (libc6) => /lib32/libstdc++.so.6

搜半天,有的说安装 build-essential 等等,检查已经安装了还是不行,最后找到 Intel 的一个客户支持记录 ,里面有一层回复提到

This error could arise when you have multiple gcc packages installed in your system and the compiler is unable to locate the correct system libraries.
In one of the cases, I have gcc-11 and g++ -11 installed in my system, I did not face any issues while building. Thereafter, I have installed gcc-12 in my system, then the same error was reproduced while building with cmake.
This issue was resolved after installing g++ -12 in my system. You can install g++ -12 by running the following commands in the terminal.

居然是因为系统里装了多个 gcc 版本,检查了下还真是,和回复提到的报错时环境情况一样,同时装了 gcc-11 和 gcc-12,但 g++ 只装了 11(不知道怎么搞的,好像都是 ubuntu 22.04 自带的?)
按回复里说的,sudo apt install g++-12 装上就好了……

  • 8
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值