简体   繁体   中英

iOS Static Library as a Subproject of a Project That Has Custom Build Configurations?

I'm trying to share code between multiple Xcode projects. I've followed Apple's notes on creating a static library subproject within a project:

http://developer.apple.com/library/ios/technotes/iOSStaticLibraries/iOSStaticLibraries.pdf

This works great! However, when I follow the same instructions using my own project, I find that the header files I make public in the static library can not be found by code within my app.

This is because my project uses custom build configurations. I have one for Ad Hoc builds, App Store builds, etc.

For example: when I build the project using a build config called "Ad Hoc", the static library subproject builds the Release configuration and copies its public headers to a folder called "Release". The main project then fails to build, complaining that it can't find headers that I'm importing from the static library. The errors appear in the Issue Navigator as: Lexical or Preprocessor Issue

So my question is: how do you set up a static library as a subproject of a project that has build configurations that the library doesn't?

I came across this issue when making my custom project templates.

Add "$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)" to the "Header Search Paths" and "User Header Search Paths" for any build configurations you use Archive with and make sure it is set to be "recursive" as opposed to "non-recursive". This will tell your app to search the "Release" directory in your build directory for header files.

The problem is that for Debug builds ALL header files are copied to a single directory under derived data. But when you archive the files are copied to a folder named after the build configuration. So when you do a "Ad Hoc" build all your files get copied to the "Ad Hoc" folder but your static libraries files get copied to the "Release" folder. These folders sit side by side beside one another and unless told to do so the header files will only be searched for under the "Ad Hoc" folder.

Here is the GitHub commit for my project templates where I fixed the problem https://github.com/reidmain/Xcode-5-Project-Templates/commit/e465aa3d5c82118cc0d5af3a7f6f094d86b1ec63

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM