【问题标题】:Can i create a shared lib which has both shared and static library我可以创建一个具有共享库和静态库的共享库吗
【发布时间】:2011-01-09 01:39:50
【问题描述】:

我正在尝试创建一个共享库,它在内部链接到许多共享库和一个静态库。就我而言,我的共享库不包括 static lib 。我想知道我在尝试什么是否正确,或者我需要将静态库转换为共享库然后进行链接。

我需要知道是否有任何 makefile 标志允许我添加静态库和共享库。

请提出建议。

【问题讨论】:

  • 您帖子的标志需要更具体(库...)
  • 您需要向我们展示您是如何执行链接的。
  • 有没有办法在不包括静态库的情况下进行链接?
  • 我在 AIX 机器上工作,我正在使用 -Ldir -llibname 选项进行链接。不,我不能跳过这个库,唯一的方法是将它转换为共享库,但它是第 3 方库,所以我无权访问源代码。
  • @wizard:是的,你只需要再创建一个包含依赖静态库的dll库。

标签: makefile shared-libraries static-libraries


【解决方案1】:

您可以创建一个依赖于其他库(静态和动态)的库。但是你需要在你的内部集成静态库部分(因为这个不能动态加载)

dependence of your source code:
your_library -> static_library.lib
your_library -> dynamic_library.dll

how you implement can it (to be used by an executable):

your_library.dll (which contain your_library and static_library source code)
dynamic_library.dll (to distribute with your_library.dll)

or

your_library.dll
static_library.dll (to be created from the static_library.lib)
dynamic_library.dll (to distribute with your_library.dll)

编辑:这可能是您正在寻找的convert static library to shared library(它适用于 linux,但您将拥有相同的操作系统):

.a files are just archives of .o object files, so all you need to do is unpack the archive and repackage them as a shared object (.so)
ar -x mylib.a
gcc -shared *.o -o mylib.so

【讨论】:

    猜你喜欢
    • 2011-08-27
    • 1970-01-01
    • 1970-01-01
    • 2021-03-18
    • 2012-02-07
    • 2010-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多