简体   繁体   English

使用未解析的符号链接静态库

[英]Linking against static library with unresolved symbols

I have a static library libA.a which contains unresolved symbols (they are also available in another static library libA_dep.a) 我有一个静态库libA.a,其中包含未解析的符号(它们在另一个静态库libA_dep.a中也可用)

I create another shared library libB.so which is linked against libA.a 我创建了另一个与libA.a链接的共享库libB.so

When the user links her program against libB.so she also needs to link against libA_dep.a, otherwise there are unresolved symbols. 当用户将程序链接到libB.so时,她还需要链接libA_dep.a,否则会有未解析的符号。 For licensing reasons I cannot release libA_dep.a to the user. 出于许可原因,我无法将libA_dep.a释放给用户。 Is there a way to work-around this? 有办法解决此问题吗? (eg, to link the libB.so with libA_dep.a and tell the linker to place those symbols into the .so) (例如,将libB.so与libA_dep.a链接,并告诉链接器将这些符号放入.so中)

You can do the following, but this will be quite a bit of work: 您可以执行以下操作,但这将需要大量工作:

Create an empty .cpp containing nothing, compile it. 创建一个不包含任何内容的空.cpp进行编译。 Then link it with the static library, using the --whole-archive option, to produce the shared library. 然后使用--whole-archive选项将其与静态库链接,以生成共享库。 This, essentially, converts the static library to an .so . 本质上,这会将静态库转换为.so

What this will end up doing is creating a shared library containing all the code from the static library that your own code uses. 最终将要做的是创建一个共享库,其中包含您自己的代码使用的静态库中的所有代码。 Then, you link your main application with the shared library instead of the static library. 然后,将主应用程序与共享库而不是静态库链接。

You will have to provide the same script that you used to your customer, so that they, themselves, can legally obtain that static library, and convert it to the same shared library that you did, allowing them to run your code that was built against the shared library version. 您将必须提供与客户相同的脚本,以便他们自己可以合法地获取该静态库,并将其转换为与您相同的共享库,从而允许他们运行针对其构建的代码共享库版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM