如何共享库结合? [英] How to combine shared libraries?

查看:119
本文介绍了如何共享库结合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些我想合并成一个共享库的.so 库,以便它不依赖于原的.so 文件了。

I've got some .so libraries that I'd like to combine into one shared library so that it doesn't depend on the original .so files anymore.

的.so 文件有依赖对方。

我怎样才能做到这一点?我可以这样做吗?

How can I do this? Can I do this?

推荐答案

这里假设你有源$ C ​​$ C到所有共享对象:

只要没有命名空间冲突(这不应该有,如果这两个并存的,因为它是),就不会太可怕很难将其纳入一个共享的对象。

Provided there are no name space conflicts (which there should not be if the two co-exist as it is), it would not be too terribly hard to build them into one shared object.

如果共享库本身依赖于code从另一个库,为了这件事情影响。真正的工作才刚刚在makefile制定出相关性。我从来没有见过在SO的成功链接循环依赖,所以我怀疑你有他们首先。即富()取决于杆(),它依赖于foo的()。

If the shared libraries themselves depend on code from another library, order is going to matter. The real work is just getting the dependencies worked out in the makefile. I've never seen circular dependencies in SO's successfully link, so I doubt that you have them to begin with. I.e. foo() depends on bar() which depends on foo().

我已经做了好几次,虽然库本身是微不足道的。我把零件从美国贸易代表办公室(字符串处理函数),配置文件处理程序,其他的一些自定义分析器等实用功能,并创建一个自定义的混搭。

I've done this several times, though the libraries themselves were trivial. I took parts from ustr (string handler), a configuration file handler, some other custom parsers and other utility functions and created a custom mash up.

真正的痛苦带来的每一上行改进一旦你将它们结合在一起,但我不知道如果这是你的问题。

The real pain is bringing in upstream improvements to each once you have combined them, however I'm not sure if that's an issue for you.

所以,如果您有:

libfoo.so: $(LIB_FOO_OBJECTS) $(LIB_BAR_OBJECTS) $(LIBFOOBAR_OBJECTS)

其中:

LIB_FOO_OBJECTS = \
     $(libfoo)/foo.o \
     $(libfoo)/strings.o

LIB_BAR_OBJECTS = \
     $(libbar)/bar.o
 ....

...和顺序是正确的..其余为pretty容易。注意:我没有表现出头DEPS,每个人都该有点不同。使得混搭时,虽然,因为你可能想避免重新编译整个图书馆每次一个头的变化他们是非常重要的。

... and the order is correct .. the rest is pretty easy. Note I didn't show header deps, everyone does that a little differently. They are important when making mash-ups though, as you'd probably want to avoid recompiling the whole library every time one header changes.

注:如果所有三个项目正在使用自动工具..你的任务只是得到成倍容易(或困难)根据

NB: If all three projects are using autotools .. your task just got exponentially easier (or harder) depending.

如果您不具有源$ C ​​$ C

如果有每个库的静态版本,您可以提取对象,并使用它们。即:

If there is a static version of each library, you may be able to extract the objects and use them. I.e.:

$ cp /usr/lib/foo.a ./foo.a
$ ar x foo.a
$ gcc -fPIC -shared *.o -o foo.so

当然更为其相当多的参与不是说明作者

Of course its quite a bit more involved than illustrated.

我从来没有试过,不知道如何处理战略目标具有main()中,当谈到在这种情况下连接。

I have never tried that and don't know how to handle SOs that have main() when it comes to linking in that case.

这篇关于如何共享库结合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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