Xcode 4 can’t locate public header files from static library dependency

Each of the solutions I’ve seen to this problem have either seemed inelegant (copying headers into the application’s project) or overly simplified to the point that they only work in trivial situations.

The short answer

Add the following path to your User Header Search Paths

“$(BUILD_ROOT)/../IntermediateBuildFilesPath/UninstalledProducts”

Why does this work?

First, we need to understand the problem. Under normal circumstances, which is to say when you Run, Test, Profile or Analyze, Xcode builds your project and puts the output in the Build/Products/Configuration/Products directory, which is available via the $BUILT_PRODUCTS_DIR macro.

Most guides regarding static libraries recommend setting the Public Headers Folder Path to $TARGET_NAME, which means that your lib file becomes $BUILT_PRODUCTS_DIR/libTargetName.a and your headers are put into $BUILT_PRODUCTS_DIR/TargetName. As long as your app includes $BUILT_PRODUCTS_DIR in its search paths, then imports will work in the 4 situations given above. However, this will not work when you try to archive.

Archiving works a little differently

When you archive a project, Xcode uses a different folder called ArchiveIntermediates. Within that folder you’ll find /YourAppName/BuildProductsPath/Release-iphoneos/. This is the folder that $BUILT_PRODUCTS_DIR points to when you do an archive. If you look in there, you’ll see that there is a symlink to your built static library file but the folder with the headers is missing.

To find the headers (and the lib file) you need to go to IntermediateBuildFilesPath/UninstalledProducts/. Remember when you were told to set Skip Install to YES for static libraries? Well this is the effect that setting has when you make an archive.

Side note: If you don’t set it to skip install, your headers will be put into yet another location and the lib file will be copied into your archive, preventing you from exporting an .ipa file that you can submit to the App Store.

After a lot of searching, I couldn’t find any macro that corresponds to the UninstalledProducts folder exactly, hence the need to construct the path with “$(BUILD_ROOT)/../IntermediateBuildFilesPath/UninstalledProducts”

Summary

For your static library, make sure that you skip install and that your public headers are placed into $TARGET_NAME.

For your app, set your user header search paths to “$(BUILT_PRODUCTS_DIR)”, which works fine for regular builds, and “$(BUILD_ROOT)/../IntermediateBuildFilesPath/UninstalledProducts”, which works for archive builds.

Leave a Comment