如何使用gcc从ubuntu下的静态库创建共享库 [英] how to make shared library from a static library under ubuntu using gcc

查看:66
本文介绍了如何使用gcc从ubuntu下的静态库创建共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个静态库 libsrp.a,我想从中创建一个包含所有符号的共享库 libsrp.so.请告诉我如何在 ubuntu 下制作 .so.

i have a static library libsrp.a, i want to make a shared library libsrp.so from it that contains all symbols . please tell me how to make a .so under ubuntu.

谢谢

推荐答案

使用 --whole-archive 标志:

gcc -shared -o libsrp.so -Wl,--whole-archive -lsrp -Wl,--no-whole-archive

来自 ld 手册页(我的重点):

--整体存档对于 --whole-archive 选项后命令行中提到的每个存档,将存档中的每个目标文件都包含在链接中,而不是在存档中搜索所需的目标文件.这通常用于将存档文件转换为共享库,强制将每个对象都包含在生成的共享库中.此选项可以多次使用.

--whole-archive For each archive mentioned on the command line after the --whole-archive option, include every object file in the archive in the link, rather than searching the archive for the required object files. This is normally used to turn an archive file into a shared library, forcing every object to be included in the resulting shared library. This option may be used more than once.

这篇关于如何使用gcc从ubuntu下的静态库创建共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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