views:

73

answers:

3

Hi all,
Here is the situation I have:
ProjectA - Xcode static library project.
ProjectA contains logical code group ExternLib with file ExternLib.h. ExternLib.h itself is in the folder Classes/lib/ExternLib (relative to ProjectA folder). Within ProjectA, I use ExternLib.h simply as: #import "ExternLib.h". This works fine.

Next I have ProjectB. This includes ProjectA as a linked Xcode project. The target has been added correctly etc. However, when I include a file in ProjectB which in turn includes ExternLib.h, upon building ProjectB, I get an error saying that the file ExternLib.h cannot be found.

I have tried adding the path to ExternLib.h to the header search path (all types: relative, absolute, with recursion etc.) but to no avail. I have checked that static library target has the copy headers step and the file ExternLib.h is included in it.

Anybody able to shed some light on how to get around this?

Cheers Naren

A: 

It's really hard to say what might have gone wrong.

I'd start from scratch with a tutorial on building and using static libraries, and see if any of the steps jog any ideas out of you.

Kendall Helmstetter Gelner
+1  A: 

1) Add a Run Script Build Phase to the target for ExternLib that executes mkdir -p "${BUILT_PRODUCTS_DIR}ExternLibHeaders"

2) Add a Copy Files build phase that copies the ExternLib header files into "${BUILT_PRODUCTS_DIR}ExternLibHeaders", and add all of ExternLib's headers into that phase.

3) In the app target for ProjectB, add "${BUILT_PRODUCTS_DIR}/ExternLibHeaders/" to the Header Search Paths for all configurations.

4) In Xcode > Preferences > Build, set the Build Products Directory to some common location.

The fourth step is crucial; it ensures that BUILT_PRODUCTS_DIR is the same for both projects.

cdespinosa
This was helpful. But it turned out my header paths were not getting read properly (no idea why). I ended up reverting all project changes and then adding to the header paths in the configuration. Everything then worked fine. Thank you for your time. Naren
Naren
A: 

I've created a complete tutorial on how to create and use static libraries, this tutorial covers the the method that is also advised by apple, maybe people will find it useful:

http://www.sodeso.nl/?p=822

Advantages of this methods is that it automatically recompiles the library according to your project settings (so no trouble with device / simulator builds)

ronaldmathies