iPhone - 使用静态库?
我创建了一个静态库项目,它生成一个“a”文件。 我将这个“a”文件作为静态库包含到另一个项目中。
我可以使用这个静态库中的类的唯一方法是复制所有头文件以及“a”文件。
是否可以避免复制头文件,并且仍然能够使用和导入此静态库中的类?
I created a static library project which generates an "a" file.
I included this "a" file to another project as a static library.
The only way I could use the classes in this static library was to copy all header filed over as well as the "a" file.
Is it possible to avoid copying the header files, and still be able to use and import classes from this static library?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能找到的最好的选择是在这里:
http ://www.cocoanetics.com/2010/05/making-your-own-iphone-frameworks-in-xcode/
...基本上,您可以跳过一些步骤将静态库打包为 框架。该框架将创建头文件的内部副本,因此当您将其包含在项目中时,您可以自动访问它们。
The best option I could find is here:
http://www.cocoanetics.com/2010/05/making-your-own-iphone-frameworks-in-xcode/
...basically, you can jump through a few hoops to package your static library as a Framework. The Framework will create an internal copy of your header files, so you get access to them automatically when you include it in your project.
事实并非如此,您必须在调用者可见的地方声明函数。头文件是最方便的方法,因为它提供了一个接口。一种可能的方法是将这些标头合并到一个 .h 文件中,这样您就可以为库提供一个单一且完整的接口。
我能想到的唯一其他方法是在调用函数的文件中声明函数,但这比包含头文件更具破坏性且更容易出错。
Not really, you have to declare the functions somewhere visible to the caller. Header file is the most convenient way to do it, because it provides an interface. A possible approach is to merge those headers into one .h file, so you provide a single and complete interface with your library.
The only other approach I can think about is declaring the functions in the files where you call them, but this is much more devastating and error prone then including a header file.