ld 找不到要链接的库
下面举个例子来描述我的问题:
ld -Lpath1 -Lpath2 -lA -lB -Xlinker -T -Xlinker \
-W1,-rpath,/usr/local/lib -l-o target
ld: cannot find -lA
collect2: ld returned 2 exit status
path1和path2都是相对路径,我根据ld的pwd可以找到库A,那么ld为什么会输出这个错误消息呢?
谁能给我一些建议来调试这个问题?
我想念一些,在名为 rt 的库之前有一个“-static”。
根据您的建议,我尝试让 gcc 驱动 ld 进行链接过程。 gcc 奥博 -mabi=64 -static -lrt -Xlinker -T -Xlinker ld.script -W1,-rpath,/usr/local/lib -lmemdbg -o target 它不起作用。
然后我删除“-static”选项,以及-lpthread之后的另一个动态库(因为rt依赖于当我删除“-static”时发现的pthread)
gcc Ao Bo -mabi=64 -lrt -lpthread -Xlinker - T -Xlinker ld.script -W1,-rpath,/usr/local/lib -lmemdbg -o 目标 这次,对象已成功链接在一起。
然后我尝试通过将“-v”传递给 gcc 来弄清楚为什么“-static”命令不起作用 。出现了一些“-L”选项,并在搜索列表中找到了一个名为 librt.a 的库。
我真的很困惑。 gcc的版本是4.3
The following is an example to describe my problem:
ld -Lpath1 -Lpath2 -lA -lB -Xlinker -T -Xlinker \
-W1,-rpath,/usr/local/lib -l-o target
ld: cannot find -lA
collect2: ld returned 2 exit status
Both path1 and path2 are relative paths, and I can find the library A according to the ld's pwd, so why did the ld output this error msg?
Could anyone give me some suggestion to debug this problem?
i miss some, there is a "-static" before a library called rt.
As your suggestion, i try to let gcc drive the ld to do linking process.
gcc A.o B.o -mabi=64 -static -lrt -Xlinker -T -Xlinker ld.script -W1,-rpath,/usr/local/lib -lmemdbg -o target
it don't work.
and then i remove the "-static" option, and another dynamic lib after -lpthread(because rt depend on pthread which is found when i remove the "-static")
gcc A.o B.o -mabi=64 -lrt -lpthread -Xlinker -T -Xlinker ld.script -W1,-rpath,/usr/local/lib -lmemdbg -o target
and this time, the objects is linked together successfully.
and then i try to figure out why the "-static" command don't work by passing a "-v" to gcc
. some "-L" option appeared, and do find a lib called librt.a in the search list.
i really confused. the version of gcc is 4.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有多种问题可能是影响因素:
path1/libA.a
?path1/libA.so
?-W1
选项可能应该是-Wl
,但这不能解释链接错误。-lo
选项可能应该是两个带有-l
选项参数的选项(除非您确实有一个库lib-oa
或 <代码>lib-o.so)。main()
- 并且仅在经典 Unix 而不是 Linux 系统上。There are various issues that could be factors:
path1/libA.a
?path1/libA.so
?-W1
option should probably be-Wl
, but that would not account for the link error.-l-o
option should probably be two options with an argument for the-l
option (unless you really have a librarylib-o.a
orlib-o.so
).main()
for you - and that only on classic Unix and not Linux systems.ld
directly than when using the compiler instead.