3

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?

2 Answers 2

1
  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.

Sign up to request clarification or add additional context in comments.

1 Comment

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
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.