c++ - ld : cannot find -lstdc++

标签 c++ linker g++

我试图将编译分解为这四个步骤,但最后一个步骤对我来说似乎有问题。

cpp hello.cpp > hello.i
g++ -S hello.i
as -o hello.o hello.s
ld -o hello hello.o -lstdc++

我在 here 上搜索了这个问题和 here ,但这没有帮助。

在详细模式下运行给了我

attempt to open hello.o succeeded
hello.o
attempt to open /usr/i686-linux-gnu/lib32/libstdc++.so failed
attempt to open /usr/i686-linux-gnu/lib32/libstdc++.a failed
attempt to open //usr/local/lib32/libstdc++.so failed
attempt to open //usr/local/lib32/libstdc++.a failed
attempt to open //lib32/libstdc++.so failed
attempt to open //lib32/libstdc++.a failed
attempt to open //usr/lib32/libstdc++.so failed
attempt to open //usr/lib32/libstdc++.a failed
attempt to open //usr/local/lib/i386-linux-gnu/libstdc++.so failed
attempt to open //usr/local/lib/i386-linux-gnu/libstdc++.a failed
attempt to open //usr/local/lib/libstdc++.so failed
attempt to open //usr/local/lib/libstdc++.a failed
attempt to open //lib/i386-linux-gnu/libstdc++.so failed
attempt to open //lib/i386-linux-gnu/libstdc++.a failed
attempt to open //lib/libstdc++.so failed
attempt to open //lib/libstdc++.a failed
attempt to open //usr/lib/i386-linux-gnu/libstdc++.so failed
attempt to open //usr/lib/i386-linux-gnu/libstdc++.a failed
attempt to open //usr/lib/libstdc++.so failed
attempt to open //usr/lib/libstdc++.a failed
ld: cannot find -lstdc++

有什么建议吗?提前致谢。

最佳答案

不要直接调用链接器,而是尝试通过 gccg++ 间接调用它:

cpp hello.cpp > hello.i
g++ -S hello.i
as -o hello.o hello.s
g++ -o hello hello.o

关于c++ - ld : cannot find -lstdc++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27241827/

相关文章:

c++ - 调试链接错误的最佳实践

c++ - 无法使用 Magick++ 编译代码(库问题)

c++ - 数值 vector 运算符重载+右值引用参数

c++ - 为什么标准类不对不可复制类型使用 static_assert?

c++ - g++ 对构造函数的 undefined reference

c++ - 链接器是否存在于所有编译的编程语言中?

c++ - 对 cv::Mat::Mat() 的 undefined reference

visual-c++ - 如果使用 Visual-C++ 或 gnu g++ 编译,此函数会给出不同的结果

C++如何获取键盘按键值(或数字/代码)

c++ - std::queue 生产者/消费者的最小互斥体