简体   繁体   English

如何在另一个静态库中添加一个静态库.a文件

[英]How to add one static library .a file in another static library

我正在创建一个应用程序,因为我要添加一个第三方库。并且我创建了一个静态库。所以现在我想将我的库包含到该第三方库中。如果我在添加到我的应用程序中之前编译了该第三方库,它只会为这两个文件创建单个.a文件,或者我必须在另一个示例应用程序的.a文件中包含我的库.a文件以及第三方文件。如果要创建单个.a文件,则.h文件是什么我必须仅包括第三方库.h文件或我的库.h文件。

Static libraries are not embedded into one another, if this is what you are asking. 如果您要的是静态库,则不会相互嵌入。

A static library is just a collection of object files, each corresponding to a compilation unit (eg, your .m files). 静态库只是对象文件的集合,每个对象文件对应一个编译单元(例如,.m文件)。

In practice, you can disassemble two static libraries to extract all the component object files and then reassemble those in a new static library, but this is not what the compiler does normally. 在实践中,您可以反汇编两个静态库以提取所有组件对象文件,然后在新的静态库中重新组装它们,但这不是编译器通常执行的操作。

So, say you have a static library lib1.a that depends on a second static library lib2.a; 因此,假设您有一个静态库lib1.a,它依赖于第二个静态库lib2.a; you create an executable by linking both libraries with your main function. 您可以通过将两个库与您的main功能链接来创建可执行文件。 Unless you manually "merge" the two libraries, each time you want to use lib1.a, you will also need to link lib2.a. 除非您手动“合并”这两个库,否则每次您要使用lib1.a时,还需要链接lib2.a。

This can be checked really easily in Xcode. 这可以在Xcode中非常容易地检查。

As to header files, you need to include the header files for both libraries, as well. 至于头文件,您还需要包括两个库的头文件。

If you want more information about merging two static library in order to create a new static library that includes the object files of both, check this or this . 如果您想了解有关合并两个静态库以创建包含两个对象文件的新静态库的更多信息,请检查thisthis

When you link one static library to another, you only need to link the resulting combined static library with your application. 将一个静态库链接到另一个静态库时,只需要将生成的组合静态库与应用程序链接。 You will need to include the headers that define public interface for your library, and those for the third party library in your application. 您将需要在应用程序中包括为库定义公共接口的头,以及为第三方库定义公共接口的头。 Any frameworks used by either your library or the third party must be linked with the application. 您的图书馆或第三方使用的任何框架都必须与该应用程序链接。

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

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