本文介绍了Xcode 自定义构建配置导致“找不到库/文件"对于静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作区,其中有一个项目与另一个项目(也在工作区中)中的静态库链接.这是 Kobold2D 中的问题,即使我明白原因,我也无法解决,我想是类似于这个问题.

I have a workspace with a project which links with the static libraries in another project (which is also in the workspace). It's a problem in Kobold2D I haven't been able to resolve, even though I understand the cause, and I suppose it's similar to this question.

项目目标和静态库目标都具有调试发布构建配置.一切都很好.

The project targets and the static library targets all have the Debug and Release build configurations. All is well.

现在有人在项目中添加了一个新的构建配置并将其命名为Ad-Hoc.现在项目的目标构建了Ad-Hoc 配置,但是静态库没有这样的配置.显然,他们然后默认构建发布配置.

Now someone adds a new build configuration in the project and names it Ad-Hoc for example. Now the project's target builds the Ad-Hoc configuration, however the static libraries have no such configuration. Apparently they then default to building the Release configuration.

最后,当链接器应该把所有东西放在一起时,它失败了:

At the end, when the linker is supposed to bring everything together, it fails:

ld: library not found for -lbox2d-ios
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang++ failed with exit code 1

对于通过 -force_load $(BUILT_PRODUCTS_DIR)/libSomeLib.a 强制加载的库,错误类似但显示找不到文件".我应该注意到库libbox2d-ios.a"在link binary with libraries"构建阶段列表中.

For forcibly loaded libraries via -force_load $(BUILT_PRODUCTS_DIR)/libSomeLib.a the error is similar but says "file not found". I should note that the library "libbox2d-ios.a" is in the "link binary with libraries" build phase list.

显然,问题在于链接器假设库位于 BUILT_PRODUCTS_DIR 的 Ad-Hoc-iphoneos 文件夹中,而实际上它们位于 Release-iphoneos文件夹,因为它们没有 Ad-Hoc 构建配置.

Obviously the problem is that the linker is assuming that the libraries are in the Ad-Hoc-iphoneos folder in the BUILT_PRODUCTS_DIR while they are actually in the Release-iphoneos folder because they have no Ad-Hoc build configuration.

我怎样才能拍打链接器的脸并告诉他将库放在它们所在的位置?最好我正在寻找适用于这两种情况的解决方案,即库添加了标准方式(链接二进制与库构建阶段)和需要额外 -force_load 才能工作的库.

How can I slap the linker in the face and tell him to get the libraries where they are? Preferably I'm looking for a solution that works for both cases, ie libraries added the standard way (link binary with libraries build phase) and libraries that need an additional -force_load to work.

我希望有一些方法可以:

I'm hoping that there's some way to:

  • 强制库放置在应用目标的构建配置文件夹中
  • 运行后编译 &将每个库复制到构建配置文件夹的预链接脚本
  • 指定库的相对路径
  • 对 -force_load 使用除 $BUILT_PRODUCTS_DIR 之外的不同宏
  • 像 -WTFmake-all-problems-go-away 这样的链接器标志

对不起,但我必须说这个......ARGH! :)

Excuse me, but I have to say this … ARGH! :)

推荐答案

很遗憾,我还没有找到解决方案.我能找到的最佳解决方法是添加新目标而不是新的构建配置.例如,在我的一个项目中,我只有 Release 和 Debug 配置,但我有额外的目标,称为MyProject - app store"和MyProject - ad hoc".当然,这只有在您可以控制项目文件的情况下才有可能.

I have not found a way to do this, unfortunately. The best workaround I can find is to add new targets rather than new build configurations. So for example in one of my projects I have only Release and Debug configurations, but I have extra targets called "MyProject - app store" and "MyProject - ad hoc". This will only be possible if you have control of the project file, of course.

有重复的目标在极端情况下很烦人,因为您可以将文件添加到一个目标而忘记将它们添加到其他目标,并且在尝试构建它之前您不会知道.但它确实构建了,这是一个胜利(无论如何使用 xcode).

Having duplicated targets sitting around is annoying in the extreme because you can add files to one target and forget to add them to the others, and you won't know until you try and build it. But it does build, which is a win (with xcode anyhow).

我前段时间问过的一个类似问题:使用静态库在 ios 项目中设置构建配置以在 xcode 4 中创建存档的正确方法是什么?

A similar question I asked a while ago: What is the correct way to set build configurations in an ios project using static libraries for creating an archive in xcode 4?

这篇关于Xcode 自定义构建配置导致“找不到库/文件"对于静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:17