xcode 向 iPhone 项目添加静态库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/767429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:32:13  来源:igfitidea点击:

Adding a static library to an iPhone project

iphonexcodestatic-librariesopenldap

提问by Ade St John-Bee

The motivation for this question is me trying to get LDAP functions to work with an iPhone application which is a project I'm attempting for part of my dissertation.

这个问题的动机是我试图让 LDAP 函数与 iPhone 应用程序一起工作,这是我在论文的一部分中尝试的项目。

When I was developing the application I used the ldap.framework framework that is part of Mac OS X. This works fine in the simulator, but when I try to now get the app on a device it tells me that I'm not allowed to use this framework.

当我开发应用程序时,我使用了 ldap.framework 框架,它是 Mac OS X 的一部分。这在模拟器中运行良好,但是当我现在尝试在设备上获取应用程序时,它告诉我我不允许使用这个框架。

After some research I found that I could build openldap using the arm architecture and add the static library to my application destined for my device.

经过一些研究,我发现我可以使用 arm 架构构建 openldap 并将静态库添加到我的应用程序中,以我的设备为目标。

I eventually managed to compile configure and build openldap by setting variables as mentioned hereand using the following commands...

我最终设法通过设置这里提到的变量并使用以下命令来编译配置和构建 openldap ...

Ade$ ./configure CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-4.0.1 \
LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin --with-yielding_select=yes
Ade$ make depend
Ade$ make

I was told that the file I'm looking for will have an extension of '.a' so I searched for a '.a' file that mentions ldap...

有人告诉我,我要查找的文件的扩展名为“.a”,所以我搜索了一个提到 ldap 的“.a”文件...

Ade$ sudo find / -name *ldap*.a
Password:
/Users/Ade/Desktop/openldap-2.4.16/libraries/libldap/.libs/libldap.a
/Users/Ade/Desktop/openldap-2.4.16/libraries/libldap_r/.libs/libldap_r.a

So I assume these are the files I need?

所以我假设这些是我需要的文件?

My question is what do I do next? I know I need to add the library to the Xcode project and probably add a load of '.h' files too?

我的问题是接下来我该怎么做?我知道我需要将库添加到 Xcode 项目中,并且可能还需要添加大量“.h”文件?

If anyone can give me a pointer to documentation or shed any light on the next stage I would be really grateful.

如果有人能给我一个指向文档的指针或对下一阶段有所了解,我将不胜感激。

Many thanks, Ade

非常感谢,阿德

ps. I have also talked about this process on my blog at www.greenpasta.com.

附:我也在我的博客www.greenpasta.com上谈到了这个过程。

回答by Rob Napier

I've done this same thing to build an LDAP client for the iPhoneOS 2.2. You just to drag the .a into the "link with libraries" build stage. I recommend using the regular (non _r) version of the library, unless you specifically need reentrancy on your ldap stuff (which I don't recommend). You can also add the .h's to your project, which is generally the easiest way to access them.

我已经做了同样的事情来为 iPhoneOS 2.2 构建一个 LDAP 客户端。您只需将 .a 拖入“链接库”构建阶段。我建议使用库的常规(非 _r)版本,除非您特别需要对 ldap 内容进行重入(我不推荐)。您还可以将 .h 添加到您的项目中,这通常是访问它们的最简单方法。

回答by Rog

Simply drag the .a files into the Xcode project and choose "copy files into project". I'm not familiar with OpenLDAP but I think the _r version is just a threadsafe version. I would recommend using that and not copying the other. You should probably not copy both files into Xcode or you will get link errors.

只需将 .a 文件拖到 Xcode 项目中,然后选择“将文件复制到项目中”。我不熟悉 OpenLDAP,但我认为 _r 版本只是一个线程安全版本。我建议使用它而不是复制另一个。您可能不应该将这两个文件都复制到 Xcode 中,否则会出现链接错误。

Then do the same for the .h files that define the client APIs of OpenLDAP - again I'm not sure which these are but I'm sure you can find out easily.

然后对定义 OpenLDAP 的客户端 API 的 .h 文件执行相同的操作 - 同样,我不确定这些是哪些,但我相信您可以轻松找到。

I would advise organising the .a and .h files together in a Xcode group under resources.

我建议在资源下的 Xcode 组中将 .a 和 .h 文件组织在一起。

Include the header files in your source and you should be good to go.

在你的源代码中包含头文件,你应该很高兴。

回答by Marc W

You may also need to add -lldap to your linker command (in the build settings pane).

您可能还需要将 -lldap 添加到您的链接器命令(在构建设置窗格中)。