ld 链接问题:/usr/bin/ld: 找不到 [libraryname]
我使用 Qmake 在 Ubuntu 9.10 上构建一个共享库
这个共享库 (A) 依赖于另一个共享库 (B)。
B项目已成功建设。
在项目 A 的 .pro 文件中,我的 LIBS 变量如下所示:(
LIBS += -L../datelib/bin -llibdatelib_release.so.1.0.0
我使用了完整的 shlib 名称,因为库版本不同。)
无论如何,当我尝试构建项目 A 时,它会在链接阶段中断,并打印错误消息:
/usr/bin/ld: cannot find -llibdatelib_release.so.1.0.0
collect2: ld returned 1 exit status
make[1]: ***[bin/libprojecta_release.so.6.0.0] Error 1
make ***[release] Error 2
Exited with code 2
从错误消息中,我认为 ld 抱怨它无法找到 libdatelib 文件,所以我手动将其复制到 /usr/lib/
但是,这并没有解决问题,我得到了相同的错误消息。
有人知道如何解决这个问题吗?
[编辑]
我对使用 gcc 进行构建还很陌生。我知道如何创建符号链接,但是我应该为 lnk 命令使用哪些路径?我想要链接到的文件位于 /home/username/work/cppdev/datelib/bin 中。
另外,我使用的构建系统(qmake)会自动创建符号链接作为构建的一部分,因此我的 /home/username/work/cppdev/datelib/bin 文件夹中已经有以下文件:
- libdatelib_release.so (符号链接)
- libdatelib_release.so.1(符号链接)
- libdatelib_release.so.1.0(符号链接)
- libdatelib_release.so.1.0.0(共享库)
我可能不得不问另一个问题来解释为什么有这么多符号链接(有什么意义?) ,以及为什么我不能直接链接到共享库,而必须通过符号链接。我读过一些在线文档,但到目前为止我所看到的似乎更像是格言/传统,而不是实际的技术原因为什么在 Linux 上链接时需要这种抽象级别。
Im using Qmake to build a shared library on Ubuntu 9.10
This shared library (A) has a dependency on another shared library (B).
project B has been successfully built.
in the .pro file for project A, my LIBS variable looks like this:
LIBS += -L../datelib/bin -llibdatelib_release.so.1.0.0
(I used the full shlib name because the library versions are different.)
In any case, when I attempt to build project A, it breaks at the linkage stage, and prints the error message:
/usr/bin/ld: cannot find -llibdatelib_release.so.1.0.0
collect2: ld returned 1 exit status
make[1]: ***[bin/libprojecta_release.so.6.0.0] Error 1
make ***[release] Error 2
Exited with code 2
From the error message, I thought ld was complaining that it could not locate the libdatelib file, so I manually copied it to /usr/lib/
however, that did not solve the problem, and I am getting the same error message.
Anyone knows how to fix this?
[Edit]
I'm quite new to building using gcc. I know how to create symbolic links, but which paths do I use for the lnk command?. The file I want to link to is in /home/username/work/cppdev/datelib/bin.
Also the build system I use (qmake), automatically creates symbolic links as part of the build, so I already have the following files in my /home/username/work/cppdev/datelib/bin folder:
- libdatelib_release.so (sym link)
- libdatelib_release.so.1 (sym link)
- libdatelib_release.so.1.0 (sym link)
- libdatelib_release.so.1.0.0 (shared lib)
I may have to ask another question to explain why there are so many symlinks (whats the point?), and why I cant just link directly to a shared lib, but have to go through a symbolic link. I've read some online docs, but what I've seen so far seems more like dictum/tradition rather than actual technical reasons WHY this level of abstraction is required when linking on Linux.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你不能那样使用 -l 。 -l 只能通过 -lFOO 查找名称类似于 libFOO.so 的内容。如果您想在构建中像这样指定版本号,则需要一个不带版本号的符号链接。
比如:
现在 -lthing 就能工作了。
You can't use -l that way. -l can only find things with names like libFOO.so, via -lFOO. You need a symbolic link without the version number if you want to specify it like this in the build.
Something like:
Now -lthing will work.
前缀“lib”会自动添加到库名称中 - 使用:
The prefix 'lib' is automatically added to the library name - use:
您可以提供完整路径。 ie
但是我建议您按照 bmargulies 的建议进行操作:创建符号链接并添加 -ldatelib_release
You may provide full path. i.e.
However I would recommend you to do what bmargulies suggested: create symolic link and add -ldatelib_release