简体   繁体   English

如何将所有链接依赖项打包到一个Linux静态库中?

[英]How do you package all link dependencies into a single Linux static library?

I'm publishing a multi-platform library and it's working everywhere except Linux. 我正在发布一个多平台库,除了Linux之外,它都可以在任何地方使用。 There's probably a way to do what I need, but I'm not seeing it and hoping someone here can help. 可能有一种方法可以满足我的需求,但是我没有看到它,希望这里有人可以提供帮助。

My library consists of two projects, 'subLibrary.lib' and 'library.lib' on Windows (for example). 我的库包含两个项目,例如Windows上的“ subLibrary.lib”和“ library.lib”。 I build 'subLibrary' then link it into 'library' for distribution. 我建立“ subLibrary”,然后将其链接到“ library”进行分发。 Consumers only have to link with 'library' to get everything, including what's in 'subLibrary'. 消费者只需与“库”链接即可获得一切,包括“ subLibrary”中的内容。

Every other platform works the same -- I publish one giant 'library.a' that contains everything and consumers link with it, not having to know about any of the lower-level dependencies. 其他所有平台的工作原理都相同-我发布了一个巨大的“ library.a”,其中包含了所有内容,并且消费者与之链接,而不必了解任何较低级别的依赖项。

When building a standard executable on Linux, my link command must specify not only 'library.a' but also every dependency of it. 在Linux上构建标准可执行文件时,我的link命令不仅必须指定“ library.a”,而且还必须指定它的每个依赖项。 This is because intermediate libraries leave symbols unresolved until later. 这是因为中间库使符号直到以后都无法解析。

What I want to do is make it the same as the other platforms so the consuming executable only has to link with 'library.a' and that library contains everything it needs. 我要做的是使其与其他平台相同,因此消耗性可执行文件仅需与“ library.a”链接,并且该库包含其所需的一切。

I know this will make the library larger, but it's the only way to ensure dependency resolution and build time for everyone. 我知道这将使库更大,但这是确保依赖关系解析和为每个人建立时间的唯一方法。

On unix a library is simply a collection of all the object files. 在Unix上,库只是所有目标文件的集合。 You can add more files to the library with AR, but you do need to be careful of file name conflicts. 您可以使用AR将更多文件添加到库中,但是您确实需要注意文件名冲突。

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

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