合并多个 .so 共享库 [英] Merge multiple .so shared libraries

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

问题描述

假设我有 a.so 和 b.so.我可以将 c.so 生成为一个包含 a 和 b 导出的所有函数的单个共享库,当然可以解决所有内部依赖关系(即 b.so 的所有函数都被 a.so 调用,反之亦然)?

我试过了

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

但它不起作用.

如果我在 a.a 和 b.a 中存档 a.o 和 b.o(不应修改 a.o 和 b.o),情况也是如此,然后执行

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

谢谢

解决方案

在所有 UNIXen 上实际上不可能将多个共享库合并为一个,除了 AIX:链接器将 .so 视为最终"产品.

但是将档案合并到 .so 应该不是问题:

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

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

解决方案

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

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

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