Xcode 4中的静态库 [英] Static libraries in Xcode 4

查看:85
本文介绍了Xcode 4中的静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我的问题以前曾在这里提出,但没有可以看到的有效答案.例如

(My question has been asked here before but with no working answers that I can see. E.g. Xcode4 Workspace with Static library project & application project)

我正在尝试使用第三者提供的图书馆.他们提供了XCode项目,该项目可构建 libLibraryName.a 文件.他们建议将项目作为子项目添加到我自己的项目中,然后将产品 libLibraryName.a 文件添加到我的项目设置使用库链接二进制文件"中描述的库集中.

I'm trying to use a library provided by a 3rd party. They provide the XCode project which builds a libLibraryName.a file. They recommend adding the project as a subproject to my own, then adding the product libLibraryName.a file to the set of libraries described in my project settings "Link Binary with Libraries".

库确实正确构建:.a文件已生成.但是该项目在产品"组下显示了一个红色的 libLibraryName.a 文件.我无法使它变黑.父项目说找不到链接的 LibraryName .

The library does build correctly: the .a file is generated. But the project shows a red libLibraryName.a file under the Products group. I can't get it to turn black. And the parent project says it cant find LibraryName for linking.

作为测试,我使用XCode 4静态库模板创建了一个新的静态库项目.该项目表现出相同的行为-即使构建了.a文件,产品也从未显示黑色". (如果您是为设备而不是模拟器而构建的,它会变黑.)

As a test I created a new static library project using the XCode 4 static-library template. This project exhibits the same behavior - the product never shows up 'black' even though the .a file is built. ( it does turn black if you build for device, not simulator).

我知道XCode 4默认情况下将中间文件和产品文件放置在共享位置.我尝试了此设置,并且更改了设置以将产品文件放置在构建设置中描述的文件夹中.两种设置均无效.

I know that XCode 4 places intermediate and product files in a shared location by default. I've tried this setting, and I've changed the setting to place the product files in the folders described in the build settings. Neither setting works.

民间也建议为设备而不是模拟器而构建.我尝试了一下都没用.

Folks have also suggested building for a device rather than simulator. I've tried this to no avail.

有什么作用?如何获得一个静态库项目来识别它在哪里构建产品,然后在另一个项目中引用该产品?

What gives? How do I get a static library project to recognize where it built the product, and subsequently reference this product in another project?

推荐答案

很多箍跳,但是现在我已经注意到它可以正常工作了.

Lots of hoop jumping, but here are my notes now that it I got it working.

  • 如果您创建一个新的XCode4 iOS"Cocoa Touch静态库"项目(并向其中添加一些代码),该项目将立即可用.但是,当您进行设备构建时,产品文件 libLibraryName.a 只会变成黑色(从红色开始,表示该文件不存在).模拟器的构建并不能表明目标实际上是在构建的.

  • If you create a new stock XCode4 iOS "Cocoa Touch Static Library" project (and add some code to it) the project will build fine out of the box. But the Product file libLibraryName.a only turns black (from red, denoting the file doesn't exist) when you do a device build. A simulator build does not show that the target was built when in fact it was.

在项目目标构建设置中,"Per-Configuration Build Products Path"默认设置为$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)如果将其更改为其他名称(或者从使用作为默认值,我相信),那么产品文件 libLibraryName.a 永远不会变黑.对我来说,这表明XCode中存在一个错误.

In the project target build-settings, the "Per-Configuration Build Products Path" defaults to $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) If you change this to something else (or if you upgraded the project from XCode3.x which used $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)$(IPHONEOS_DEPLOYMENT_TARGET) as the default, I believe), then the Product file libLibraryName.a wont ever turn black. To me this says there's a bug in XCode somewhere.

我可以在构建后不让Product文件变黑的情况下生存(这是一个很好的指标,但是,嘿,不管怎样.)但是我确实需要我的耗时项目才能找到正确的库构建,适用于模拟器或设备.在理想情况下,将只有一个.a文件,其中包含i386/arm6/arm7位,但这又不是我的库/库项目.

I can live without the Product file turning black after a build (it is a nice indicator, but hey, whatever.) But I do need my consuming project to be able to find the correct build of the library, be it for simulator or device. In an ideal world there would be a single .a file with i386/arm6/arm7 bits in it, but again, this isn't my library / library project.

XCode4过渡指南是向我展示光芒的地方.它规定了创建一个托管两个项目的工作空间,并且它们都将构建到同一共享的构建目录中.我以前没有使用工作空间,所以我使用了文件/另存为工作空间命令来创建新的工作空间文件.然后,我添加了库项目,并确保将其作为我的主要项目的对等对象,而不是作为孩子放置.

The XCode4 Transition Guide is what showed me the light. It prescribes creating a workspace that hosts both of the projects, and they will both build into the same shared build directory. I was not using a workspace previously, so I used the File/Save As Workspace command to create the new workspace file. Then, I added the library project, taking care to ensure it was placed as a peer to my primary project and not as a child.

我必须确保已将工作区配置为将构建输出放置到公共文件夹中.在工作区设置"对话框中,将构建位置"设置设置为将构建产品放置在派生数据位置"

I had to make sure the workspace was configured to place build output into a common folder. In the Workspace Settings dialog, set the Build Location setting to "Place Build Products in Derived Data Location"

我还必须确保在管理方案"对话框中选中每个项目的共享"复选框.

I also had to make sure to check the "shared" checkbox for each project in the Manage Schemes dialog.

最后,要指定主项目的库依赖关系,我只需转到目标构建阶段"选项卡的使用库链接二进制文件"部分,然后单击"+",然后选择 libLibraryName.a. 文件从Workspace文件夹下面.请注意,在没有工作空间和通用构建目录的情况下,我曾尝试过此操作,结果是XCode在链接期间找不到.a文件.

Finally, to specify the library dependency for my main project, I simply went to the target Build Phases tab, Link Binaries with Libraries section, and clicked the '+', then selected the libLibraryName.a file from beneath the Workspace folder. Note that I'd tried this before when there was no workspace and no common build dir, and the result was that XCode couldn't find the .a file during link.

总而言之,它就像一种魅力.我忍不住认为它应该容易得多-因为我相信它在XCode3中.

All said and done, it works like a charm. I can't help but think it should be a lot easier - as I believe it was in XCode3.

我很乐意了解其他人在所有这些方面的经验,或者对使静态库正常工作的其他(更简单的)方法的反馈.

I'd be happy to read about anyone else's experience with all this, or any feedback about other (simpler?) ways to make linking static libs work well.

这篇关于Xcode 4中的静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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