简体   繁体   English

如何将C ++库链接到Objective-C程序

[英]How can I link a C++ library into an Objective-C program

I have a C++ Library that I'd like to link against my iPhone project. 我有一个C ++库,想链接到我的iPhone项目。 How do I do that? 我怎么做?

Just drag it in and make sure that the header files are available. 只需将其拖入并确保头文件可用。 That's it :) Make sure that the .a file (assuming that your library is a .a file) is listed on the build phases tab under "link binary with libraries". 就是这样:)确保.a文件(假设您的库是.a文件)在“构建阶段”选项卡的“与库链接二进制文件”下列出。

You have to be sure the library is built for iOS, specifically for the architecture you intend to deploy on. 您必须确保该库是为iOS构建的,特别是要用于其上部署的体系结构的库。 For instance, an Armv7 will not work on the simulator or on a pre-armv7 device like the 3G. 例如,Armv7在模拟器或3G之前的armv7之前的设备上将无法运行。 If you want this approach to work flawlessly you probably should build a .a library for all architectures, (armv6/armv7 i386) then combine them into a fat library with the "lipo" command. 如果您希望这种方法完美无缺地工作,则可能应该为所有体系结构构建一个.a库(armv6 / armv7 i386),然后使用“ lipo”命令将它们组合到fat库中。 This assumes you have access to the source, of course. 当然,这假设您有权访问源。 There was a post here on SO regarding exactly how to build a fat library from source. 关于SO的确切信息,这里有一篇帖子。 After you've done this then it would be a simple matter of drag/dropping it into Xcode along with the headers. 完成此操作后,只需将其与标头一起拖放到Xcode中即可。

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

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