xcode 静态库公共标头不会复制到 Build/Products 文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21728084/
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
Static Library public headers are not copied to Build/Products folder
提问by dimitrios
I have 2 projects, which build one static library each, as well as another project which uses both static libraries.
我有 2 个项目,每个项目都构建一个静态库,以及另一个使用这两个静态库的项目。
One of the two static libraries builds fine. The other one does not and the reason for that is that its public headers are not copied to the build folderbefore the custom shell script runs.
两个静态库之一构建良好。另一个没有,原因是它的公共头文件在自定义 shell 脚本运行之前没有复制到构建文件夹中。
Here is a demonstration of what happens:
这是发生的事情的演示:
SampleA(the one that works)
SampleA(有效的那个)
Compile MyClass1.cpp ...
Compile MyClass2.cpp ...
Libtool /Users/user/Library/Developer/XCode/DerivedData/.....
Libtool /Users/user/Library/Developer/XCode/DerivedData/.....
Libtool /Users/user/Library/Developer/XCode/DerivedData/.....
Create universal binary libSampleA.a ...
Copy SampleA.h ...in /Users/user/....
Copy MyClass1.h ...in /Users/user/....
Copy MyClass2.h ...in /Users/user/....
Run custom shell script 'Prepare Framework'
Stripping libSampleA.a
--- Build complete
SampleB(the one that does NOT work)
SampleB(不起作用的那个)
Compile OtherClass1.cpp ...
Compile OtherClass2.cpp ...
Libtool /Users/user/Library/Developer/XCode/DerivedData/.....
Libtool /Users/user/Library/Developer/XCode/DerivedData/.....
Libtool /Users/user/Library/Developer/XCode/DerivedData/.....
Create universal binary libSampleB.a ...
// >>>>> NO HEADER FILES ARE COPIED <<<<<<
Run custom shell script 'Prepare Framework'
--- Build fails (header folder does not exist)
My current setup is a workspace that includes all 3 projects, but I used to have 1 project with one nested project for each static library as well. The issue I have remains the same in both setups.
我当前的设置是一个包含所有 3 个项目的工作区,但我曾经有 1 个项目,每个静态库也有一个嵌套项目。我遇到的问题在两种设置中都保持不变。
More info
更多信息
- I have tried virtually every instruction, tip and advice I found online for making this work.
- The settings on both projects, as far as I can tell, are identical. Comparing the two project files wasn't very effective. I also haven't compared all the settings of both projects one by one to make sure they are the same (yet).
- The problem is the same in both Debug and Archive builds (I know that archiving behaves differently)
- I have added
"$(BUILD_ROOT)/../IntermediateBuildFilesPath/UninstalledProducts/include"
and/or"$(PROJECT_TEMP_DIR)/../UninstalledProducts/include"
- I have added the headers to the "Build Phases > Copy Headers > Public"section - didn't work
- I have deleted the "Build Phases > Copy Headers"phase completely, as Apple suggest and added the headers to the Copy Filesphase - didn't work
- I have added a new group in the static lib project and added all its headers, setting no target to "Add to Targets"- didn't work
- I have quit XCode and tried again, or even restart the mac - didn't work
- 我已经尝试了几乎所有我在网上找到的用于完成这项工作的说明、技巧和建议。
- 据我所知,这两个项目的设置是相同的。比较两个项目文件并不是很有效。我也没有一一比较两个项目的所有设置以确保它们是相同的(还没有)。
- 调试和存档版本中的问题是相同的(我知道存档的行为不同)
- 我已经添加
"$(BUILD_ROOT)/../IntermediateBuildFilesPath/UninstalledProducts/include"
和/或"$(PROJECT_TEMP_DIR)/../UninstalledProducts/include"
- 我已将标题添加到“构建阶段 > 复制标题 > 公共”部分 - 没有用
- 我已经完全删除了“构建阶段 > 复制标题”阶段,正如 Apple 建议的那样,并将标题添加到复制文件阶段 - 没有用
- 我在静态库项目中添加了一个新组并添加了它的所有标题,没有将目标设置为“添加到目标”- 没有用
- 我已经退出 XCode 并再次尝试,甚至重新启动 mac - 没有用
One differencebetween the two libraries is that SampleB (the one that does not build) includes various headers from SampleA. There are no compiler or linker errors, just the error at the end of the build that I describe.
两个库之间的一个区别是 SampleB(未构建的库)包含来自 SampleA 的各种标头。没有编译器或链接器错误,只有我描述的构建结束时的错误。
Sources
来源
Some of the sources I have used for the creation of the library, as well as for trying to solve the issue:
我用于创建库以及尝试解决问题的一些来源:
- https://developer.apple.com/library/ios/technotes/iOSStaticLibraries/Articles/creating.html
- Xcode 4 can't locate public header files from static library dependency
- Compile, Build or Archive problems with Xcode 4 (and dependencies)
- http://www.blog.montgomerie.net/easy-xcode-static-library-subprojects-and-submodules
- https://developer.apple.com/library/ios/technotes/iOSStaticLibraries/Articles/creating.html
- Xcode 4 无法从静态库依赖中找到公共头文件
- Xcode 4(和依赖项)的编译、构建或存档问题
- http://www.blog.montgomerie.net/easy-xcode-static-library-subprojects-and-submodules
So, do you know what triggers the headers to be copied or not be copied, during the build?
那么,您知道在构建过程中是什么触发了标题的复制或不复制?
I would suspect that even if one header file is added to the Copy Headers phase or the Copy Files phase, at least this should be copied. But as it turns out, this is not what happens, at least in my case.
我怀疑即使将一个头文件添加到 Copy Headers 阶段或 Copy Files 阶段,至少应该复制这个。但事实证明,至少在我的情况下,情况并非如此。
回答by CouchDeveloper
Following Apple's instructions, and just creating a CocoaTouch static library project from the template:
按照 Apple 的说明,从模板创建一个 CocoaTouch 静态库项目:
Ensure you have placed your custom "Run Script" phase afterthe "Copy Files" phase:
确保在“复制文件”阶段之后放置了自定义的“运行脚本”阶段:
Then, when building, the transcript will look as this:
然后,在构建时,成绩单将如下所示:
回答by CodeStage
In my setup I have a parent project with a nested project, which emits a static library.
在我的设置中,我有一个带有嵌套项目的父项目,它发出一个静态库。
I tried with a Headersphase, I couldn't get Xcode to copy the headers in the right spot when archiving. Plus the headers and the static library were copied into the archive, which you don't want. So I ended up using a Copy Filesphase and setting Skip Installto YES while pointing the Header Search Pathsin tha parent project to BUILT_PRODUCTS_DIR.
我尝试了标题阶段,但在存档时无法让 Xcode 将标题复制到正确的位置。此外,标题和静态库已复制到存档中,这是您不想要的。所以我最终使用了复制文件阶段并将跳过安装设置为是,同时将父项目中的标题搜索路径指向BUILT_PRODUCTS_DIR。