【问题标题】:ld: cannot find -lstdc++ld:找不到-lstdc++
【发布时间】:2015-01-30 06:02:06
【问题描述】:

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

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

我在herehere 上搜索了该问题,但没有帮助。

以详细模式运行给了我

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++

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

【问题讨论】:

  • g++ hello.cpp -Wl,--verbose 会让 GCC 告诉你它在哪里找到 libstdc++。这应该让您开始弄清楚如何让ld 找到它。

标签: c++ linker g++


【解决方案1】:

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

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

【讨论】:

  • 我认为这甚至可能不是间接的……ld 现在是一个不同的工具,如果我没记错的话,不推荐用于此类目的。
  • 实际上我的主要目标是学习/学习/处理链接器,而不是创建可执行文件,ld 命令让我为此哭泣。
猜你喜欢
  • 2018-12-06
  • 2012-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多