本文介绍了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.

项目目标和静态库目标都具有 DebugRelease 构建配置.一切都很好.

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

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

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"在链接二进制与库"构建阶段列表中.

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.

我希望有办法:

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

对不起,我不得不说……啊! :)

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

推荐答案

很遗憾,我还没有找到解决方法.我能找到的最佳解决方法是添加新目标而不是新的构建配置.例如,在我的一个项目中,我只有发布和调试配置,但我有额外的目标,称为MyProject - 应用商店"和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).

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

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 自定义构建配置导致“找不到库/文件";用于静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 20:14