我的情况很简单,一个包含两个同级项目的工作区:一个主 (iOS) 应用程序和一个构建应用程序使用的多个静态库目标的项目。
这是我配置构建的方式:
在清理(并删除派生数据)之后,构建在主项目的构建过程中向我发出了这个错误:
ld: library not found for -lChipmunk
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang failed with exit code 1
果然,如果我查看新创建的派生数据,找到的唯一目标文件是主应用程序,而不是库。 *.o 文件的广泛“发现”并没有揭示任何相关内容,因此这些库并没有丢失,它们肯定没有被构建。
补充几点:
我刚刚想出了一个解决方法,即将所有的 deps 目标添加到主应用程序方案的“构建”部分。我之前尝试过但没有成功,但没有意识到我可以在列表中拖动目标以获得正确的构建顺序。现在,构建以正确的顺序发生,无论是在清理之后,还是在库或主应用程序源发生更改之后。
我将问题留在这里,因为肯定不需要手动整理构建顺序。我的设置方式一定有问题。
最佳答案
编辑方案(交换构建目标,取消/选中“Parallelize Build”和/或“Find Implicit Dependencies”)对我不起作用。在静态库中的任何代码更改之后,我仍然必须清理构建项目。搜索开发论坛,我终于找到了this answer ,这创造了奇迹。
Make sure the Identity and Type inspector is showing and select the libWhatever.a file in your application's project (not the library). If you see Location: Relative to Project [or Relative to Group], this is your problem.
- Click Relative to Project and change it to Relative to Build Products.
- This will change the type of the link, but it will still be broken.
- Click the locate button and find the output file.
通过 Build Phases 将静态库添加到现有项目 -> Link Binary with Libraries 自动使其“相对于组”(如果两者都是同一个工作区)。以上述方式更改其位置可解决构建依赖问题,并且在项目导航器中,您的 .a 文件应显示为黑色字母(而不是红色)。
https://stackoverflow.com/questions/5427396/