Merge multiple .so shared libraries

牧云@^-^@ 提交于 2019-11-26 08:08:08

问题


Say I have a.so and b.so. Can I produce c.so as a single shared library with all the functions exported by a and b, of course resolving all intra-dependencies (i.e. all functions of b.so called by a.so and the other way around)?

I tried

gcc -shared -Wl,soname,c.so -o c.so a.so b.so

but it doesn\'t work.

Same goes if I archive a.o and b.o in a.a and b.a (which shouldn\'t modify a.o and b.o), and do

gcc -shared -Wl,soname,c.so -o c.so a.a b.a

Thanks


回答1:


Merging multiple shared libraries into one is indeed practically impossible on all UNIXen, except AIX: the linker considers the .so a "final" product.

But merging archives into .so should not be a problem:

gcc -shared -o c.so -Wl,--whole-archive a.a b.a -Wl,--no-whole-archive



回答2:


In practice it is not possible.

From linker point of view, a SO library is a final product that does not contain relocation information required for linking.

If you have access to either source or object files for both libraries, it is straightforward to compile/link a combined SO from them.



来源:https://stackoverflow.com/questions/915128/merge-multiple-so-shared-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!