可以静态链接共享对象库吗?
我正在构建一个需要动态链接到我的项目的库。输出是一个 .so 文件,所以我认为我走在正确的轨道上。我担心它在编译时的链接方式 - 通过指定其 makefile 的位置并依赖于一堆我以前从未遇到过的宏。
我是否可以假设,由于我正在构建一个 .so 库(而不是 .a),所以我实际上是在动态链接?或者 .so 库是否可以静态链接,在这种情况下我需要分解 make/config 文件以更好地了解发生了什么?
谢谢,
安德鲁
I'm building a library that needs to be dynamically linked to my project. The output is a .so file, so I think I'm on the right track. I'm concerned by the way it's being linked at compile time - by specifying the location of its makefile and depending on a bunch of macros, which I've never encountered before.
Can I assume that since I'm building a .so library (rather than a .a) that I'm in fact dynamically linking? Or is it possible for .so libs to be statically linked, in which case I need to rip apart the make/config files to better understand what's going on?
Thanks,
Andrew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不熟悉可执行文件和共享对象的内部结构,所以我只能给出一些实用的提示。
假设您使用
gcc
,当将目标文件链接到库时,它应该有-shared
选项 - 这样ld
(由gcc<调用) /code>) 生成共享对象而不是可执行二进制文件。
当您将某些应用程序与此 libabc.so 链接时,它应该正确链接,然后使用 ldd 命令您应该能够在其依赖项中看到 libabc.so 。
I'm not familiar with internal structure of executables and shared objects, so I could only give some practical hints.
Assuming you use
gcc
, it should have-shared
option when linking object files into library - this wayld
(called bygcc
) makes shared object instead of executable binary.When you link some application with this libabc.so it should link without errors and after that with
ldd
command you should be able to seelibabc.so
among its dependencies.