3

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?

derekvanvliet
  • 679
  • 8
  • 17
  • Are you releasing the library itself? If not why make the headers public or copy them anywhere? Surely they don't change between build types? – trojanfoe Jun 04 '13 at 13:49
  • 1
    As a trouble shooting step, try changing "include/${PRODUCT_NAME}" in the sub-project static library Copy Files panel with more simply, "include" and see if that works. It should work fine with the former, and it keeps everything neat and tidy for when a human is browsing the product directory, but it's not necessary and can cause problems if you have been fiddling about with configurations. – TheBasicMind Jun 04 '13 at 14:11
  • @trojanfoe i'm not releasing the library itself. It will be built into all of our projects. Currently the headers are getting copied to include/${PRODUCT_NAME} in the "Products Directory" destination. Do you know where I should have it copy them to so my app can see them in any build configuration? – derekvanvliet Jun 04 '13 at 16:56
  • 1
    You don't need to copy them at all; my (OSX) app which uses a C++ library, simply needs `$(PROJECT_DIR)/../mylibrary` added to the *Header Search Paths*. That's assuming that the library project is a sibling to the app project and I use a workspace to bind them all together (there are actually two library projects and an app project). – trojanfoe Jun 04 '13 at 17:30
  • @TheBasicMind I tried your suggestion but it yielded the same results. The headers were copied to a Release folder and the project failed to build. – derekvanvliet Jun 04 '13 at 17:31
  • @trojanfoe that did the trick! But won't I have issues debugging a debug-compiled version of my app with a release-compiled library? I'm wondering specifically about debugging within the library. – derekvanvliet Jun 04 '13 at 17:43
  • I don't understand your concern. – trojanfoe Jun 05 '13 at 07:01

1 Answers1

14

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

Reid Main
  • 3,394
  • 3
  • 25
  • 42