GNU/Debian Linux 和 LD
假设我有一个庞大的项目,其中包含多个动态库,这些动态库将全部安装到 /usr/lib 或 /usr/lib64 中。现在假设其中一个库调用另一个已编译的库。如果我将两个相互依赖的库放在同一位置,ld 程序是否能够允许两个库相互调用?
Lets say I have a massive project which consists of multiple dynamic libraries that will all get installed to /usr/lib or /usr/lib64. Now lets say that one of the libraries call into another of the compiled libraries. If I place both of the libraries that are dependent on eachother in the same location will the ld program be able to allow the two libraries to call eachother?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
答案也许是肯定的,但在两个库之间进行循环引用是一个非常糟糕的设计(即包含函数 fa 的
liba.so
,从libb.so
调用函数fb
,从liba.so
调用函数ga
)。您应该将这两个库合并到一个
libbig.so
中。别担心,图书馆可能很大。 (一些公司拥有数百兆代码的 Linux 库)。Debian 上的
binutils-gold
包中的gold
链接器应该对您有用。它比binutils
中的旧链接器工作得更快。The answer is perhaps yes, but it is a very bad design to have circular references between two libraries (i.e.
liba.so
containing functionfa
, calling functionfb
fromlibb.so
, calling functionga
fromliba.so
).You should merge the two libraries in one
libbig.so
. And don't worry, libraries can be quite big. (some corporations have Linux libraries of several hundred megabytes of code).The
gold
linker from packagebinutils-gold
on Debian should be useful to you. It works faster than the older linker frombinutils
.是的,只要它们的位置存在于
ld
搜索库的目录集中。您可以使用LD_LIBRARY_PATH
环境变量覆盖此集合。请参阅本手册,它将解决您的问题。
Yes, as long as their location is present in set of directories
ld
searches for libraries in. You can override this set by usingLD_LIBRARY_PATH
enviroment variable.See this manual, it will resolve your questions.
如果您指的是运行时动态链接器 /lib/ld-linux* (而不是 /usr/bin/ld),它将在 LD_LIBRARY_PATH 中查找库,其中通常包括 /usr/lib 和 /usr/lib64。
一般来说,/lib/ld-*用于运行时的.so库; /usr/bin/ld 用于编译时的 .a 库。
但是,如果您的库使用 dlopen() 或类似的方法来相互查找(例如插件),则它们可能具有其他相互查找机制。例如,许多插件系统将使用 dlopen 来读取某个(一个或多个)目录中的每个库。
If you mean the runtime dynamic linker /lib/ld-linux* (as opposed to /usr/bin/ld), it will look for libraries in your LD_LIBRARY_PATH, which typically includes /usr/lib and /usr/lib64.
In general, /lib/ld-* are used for .so libraries at run-time; /usr/bin/ld is used for .a libraries at compile-time.
However, if your libraries are using dlopen() or similar to find one another (e.g. plug-ins), they may have other mechanisms for finding one another. For example, many plug-in systems will use dlopen to read every library in a certain (one or many) directory/ies.