在 XCode 中链接到 C 库 (.a) 的正确方法是什么? [英] What is the correct way to link to a C library (.a) in XCode?

查看:42
本文介绍了在 XCode 中链接到 C 库 (.a) 的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一个我想在 iPhone 项目中使用的第 3 方库.该库是用纯 C 编写的.我编译了该库并将生成的 .a 文件添加到我的 XCode 项目中.意思是..我把文件拖到IDE中,xcode引用了它.

I found a 3rd party library that I would like to use in an iPhone project. The library is written in plain C. I compiled the library and have added the resulting .a file in to my XCode project. Meaning.. I dragged the file into the IDE and xcode made a reference to it.

我是 xcode 的新手,所以我的问题是我应该如何实际链接和使用这个库?我应该能够#include 库附带的标题并开始使用它吗?我需要为 xcode 提供一些链接器参数吗?

I am new to xcode so my question is how should I actually link to and use this library? Should I be able to #include the headers accompanying the library and start using this? Do I need to provide xcode with some linker arguments?

如果有人能指出我正确的方向,我将不胜感激.谢谢!

If someone could point me in the right direction I would appreciate it. Thanks!

更新

显然,对于我的示例来说,这真的很容易.完成上述操作后,我只是将头文件包含到我的项目中并开始使用该库.看起来效果很好.

Apparently for my example it really is that easy. After doing the above, I just included the header files into my project and started using the library. It appears to be working great.

推荐答案

如您所见,通常只需将其拖到 Xcode 中即可.当您释放 drop 时,您会得到一张表,询问您是否要将其复制到项目目录中,并且还添加了默认情况下选中目标表的添加到目标表.检查目标是神奇的部分.这样做会导致库被添加到链接构建阶段.

As you found out, dragging it into Xcode is all you usually need to do. When you release the drop you get the sheet that asks if you want to copy it the project directory and also has the add to target table which by default has the target checked. Having the target checked is the magic part. Doing so causes the library to be added to the link build phase.

如果您在添加时忘记检查目标或遇到诸如添加第二个目标并希望使用它的一些库而其他库使用第一个目标的情况,您可以通过在项目导航器中选择项目和然后是详细视图中的目标.在 Build Phases 选项卡中有 Link Binary With Libraries 阶段.它列出了目标链接的库.您可以根据需要向其中添加或删除库.

If you ever forget to check the target when adding or have a situation like you add a 2nd target and want some libraries with it while other libraries are with the first target, you can manage that by selecting the project in project navigator and then the target in the detail view. In the Build Phases tab there's the Link Binary With Libraries phase. It lists which libraries that target is linking against. You can add or remove libraries to it as needed.

这篇关于在 XCode 中链接到 C 库 (.a) 的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆