简体   繁体   English

如何在Objective-C iOS项目中使用C库?

[英]How do I use a C libary in my Objective-C iOS project?

I'm writing a program for iOS and want to use the Apache Portable Runtime and the Subversion C library in my project. 我正在为iOS编写程序,并希望在我的项目中使用Apache Portable Runtime和Subversion C库。

Since this is the first time I'm trying to do this I have no idea where to start. 由于这是我第一次尝试这样做,我不知道从哪里开始。

I already made a new C/C++ library project, imported all apr.h and svn.h files in the project, set the sdk to iOS7 我已经创建了一个新的C / C ++库项目,导入了项目中的所有apr.h和svn.h文件,将sdk设置为iOS7

It compiles well and it outputs an .a file but when I import it into my project it doesn't get linked or something. 它编译得很好,它会输出一个.a文件,但是当我将它导入我的项目时,它没有链接或其他东西。

Could anybody know a tutorial or maybe a svn library for objective c? 任何人都可以为目标c知道教程或者svn库吗? Or at least point me in a right direction. 或者至少指出我正确的方向。

The only results I get while googling it are: 我在google搜索时获得的唯一结果是:

"Objective-C should support C Libraries natively, this should be very easy" “Objective-C本应支持C库,这应该很容易”

Not so easy for me I suppose. 我想,对我来说不是那么容易。 ;) ;)

If you have the sourcecode of the C project, you can directly put all the source code into your project. 如果你有C ++项目的源代码 ,你可以直接把所有的源代码到您的项目。 Xcode knows how to compile C code and it will just be compiled with the rest of your project. Xcode知道如何编译C代码,它将只与你的项目的其余部分一起编译。

As mentioned by @Adam-Smith, you can directly interface with the C objects in your Objective-C code and the C objects will not be managed by ARC 正如@ Adam-Smith所提到的,您可以直接与Objective-C代码中的C对象进行交互,并且不会通过ARC管理C对象

This is how you can troubleshoot: 这是您可以排除故障的方法:

  1. Click your blue project icon. 单击您的蓝色项目图标。
  2. Select the Build phases tab in your main view. 在主视图中选择“构建阶段”选项卡。
  3. Expand "link with libraries". 展开“与库链接”。

Make sure your .a file is in this list. 确保您的.a文件位于此列表中。 If not add it. 如果没有添加它。

If you still have problems check your build logs (right most icon on left pane). 如果仍有问题,请检查构建日志(左侧窗格中最右侧的图标)。 The build logs contain a long list of what your compiler did. 构建日志包含编译器所做的很长的列表。 There are icons to the far right looking like 5-6 lines on top of each other. 最右边的图标看起来像是5-6行。 Actually the icon is hidden until you hover over it. 实际上,图标是隐藏的,直到你将鼠标悬停在它上面。

Clicking this will expand a compiler step and show you exactly what arguments were provided to your compiler. 单击此按钮将展开编译器步骤,并准确显示为编译器提供的参数。 This will be pretty long so it might be smart to copy to an editor. 这将是相当长的,因此复制到编辑器可能很聪明。 But it will contain switches such as -I for including header files, -L for location of libraries etc. Check that your .a file is in fact included during compilation of the code which depends on it. 但它将包含开关,例如-I用于包含头文件,-L用于库的位置等。检查您的.a文件实际上是否包含在编译依赖于它的代码期间。 Should be a -l switch I believe. 我相信应该是-l开关。

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

相关问题 我应该在我的 iOS Objective-C 项目中使用什么 Mach-O 类型? - What is Mach-O type should I use it in my iOS Objective-C project? 我应该在混合的Objective-C / Swift项目中使用Realm Objective-C或Realm Swift吗? - Should I use Realm Objective-C or Realm Swift in my mixed Objective-C / Swift project? Objective-C桥接问题。 如何在Swift项目中使用Obj-C框架? - Objective-C bridging issue. How do I use an Obj-C framework in a Swift project? 如何将iOS版pd与我的Objective-c项目链接? - How can I link pd-for-ios with my objective-c project? 如何在Objective-c中在没有ThirdParty库的情况下向我的NSString显示粗体和斜体 - How to show Bold and Italic both to My NSString without ThirdParty Libary in Objective-c 如何在iOS 7 Objective-C中摆脱此警告? - How do I get rid of this warning in iOS 7 Objective-C? 如何在iOS / Objective-C中存储身份验证密钥? - How do I store an auth key in iOS/Objective-C? 如何在Objective-c中使用SafariViewController? - How do I use the SafariViewController in Objective-c? 如何在Objective-C中使用可选的协议方法? - How do I use optional protocol methods in Objective-C? 如何将Google API Objective-C客户端库导入我的iOS项目而不会出现错误? - How can I import the Google API Objective-C Client Library in to my iOS project without getting errors?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM