可以静态链接共享对象库吗? [英] Possible to statically link shared object libraries?

查看:208
本文介绍了可以静态链接共享对象库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个需要动态链接到我的项目的库。输出是一个.so文件,所以我想我走对了。我担心它在编译时被链接的方式-通过指定其makefile的位置并取决于一堆宏,这是我从未见过的。

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.

我可以假设由于我正在构建.so库(而不是.a)而实际上是在动态链接吗?还是.so库可能是静态链接的,在这种情况下,我需要拆开make / config文件以更好地了解发生了什么?

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?

谢谢,

安德鲁

推荐答案

我对以下内容的内部结构不熟悉可执行文件和共享对象,所以我只能给出一些实用的提示。

I'm not familiar with internal structure of executables and shared objects, so I could only give some practical hints.

假设您使用 gcc ,它应该具有将目标文件链接到库时,使用共享选项-这样 ld (由 gcc )使共享对象而不是可执行二进制文件。

Assuming you use gcc, it should have -shared option when linking object files into library - this way ld (called by gcc) makes shared object instead of executable binary.

gcc -shared -o libabc.so *.o ...

当您使用此libabc链接某个应用程序时,它应该链接无误,之后使用 ldd 命令,您应该可以看到 libabc.so 的依赖项。

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 see libabc.so among its dependencies.

$ ldd app
    ...
    libabc.so => ...............

这篇关于可以静态链接共享对象库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆