Question

I have 2 projects, which build one static library each, as well as another project which uses both static libraries.

One of the two static libraries builds fine. The other one does not and the reason for that is that its public headers are not copied to the build folder before the custom shell script runs.

Here is a demonstration of what happens:

SampleA (the one that works)

Compile MyClass1.cpp ...
Compile MyClass2.cpp ...
Libtool /Users/user/Library/Developer/XCode/DerivedData/.....
Libtool /Users/user/Library/Developer/XCode/DerivedData/.....
Libtool /Users/user/Library/Developer/XCode/DerivedData/.....
Create universal binary libSampleA.a ...
Copy SampleA.h ...in /Users/user/....
Copy MyClass1.h ...in /Users/user/....
Copy MyClass2.h ...in /Users/user/....
Run custom shell script 'Prepare Framework'
Stripping libSampleA.a 
--- Build complete

SampleB (the one that does NOT work)

Compile OtherClass1.cpp ...
Compile OtherClass2.cpp ...
Libtool /Users/user/Library/Developer/XCode/DerivedData/.....
Libtool /Users/user/Library/Developer/XCode/DerivedData/.....
Libtool /Users/user/Library/Developer/XCode/DerivedData/.....
Create universal binary libSampleB.a ...
// >>>>> NO HEADER FILES ARE COPIED <<<<<<
Run custom shell script 'Prepare Framework'
--- Build fails (header folder does not exist) 

My current setup is a workspace that includes all 3 projects, but I used to have 1 project with one nested project for each static library as well. The issue I have remains the same in both setups.

More info

  • I have tried virtually every instruction, tip and advice I found online for making this work.
  • The settings on both projects, as far as I can tell, are identical. Comparing the two project files wasn't very effective. I also haven't compared all the settings of both projects one by one to make sure they are the same (yet).
  • The problem is the same in both Debug and Archive builds (I know that archiving behaves differently)
  • I have added "$(BUILD_ROOT)/../IntermediateBuildFilesPath/UninstalledProducts/include" and/or "$(PROJECT_TEMP_DIR)/../UninstalledProducts/include"
  • I have added the headers to the "Build Phases > Copy Headers > Public" section - didn't work
  • I have deleted the "Build Phases > Copy Headers" phase completely, as Apple suggest and added the headers to the Copy Files phase - didn't work
  • I have added a new group in the static lib project and added all its headers, setting no target to "Add to Targets" - didn't work
  • I have quit XCode and tried again, or even restart the mac - didn't work

One difference between the two libraries is that SampleB (the one that does not build) includes various headers from SampleA. There are no compiler or linker errors, just the error at the end of the build that I describe.

Sources

Some of the sources I have used for the creation of the library, as well as for trying to solve the issue:

So, do you know what triggers the headers to be copied or not be copied, during the build?

I would suspect that even if one header file is added to the Copy Headers phase or the Copy Files phase, at least this should be copied. But as it turns out, this is not what happens, at least in my case.

Was it helpful?

Solution

Following Apple's instructions, and just creating a CocoaTouch static library project from the template:

Ensure you have placed your custom "Run Script" phase after the "Copy Files" phase:

enter image description here

Then, when building, the transcript will look as this:

enter image description here

OTHER TIPS

In my setup I have a parent project with a nested project, which emits a static library.

I tried with a Headers phase, I couldn't get Xcode to copy the headers in the right spot when archiving. Plus the headers and the static library were copied into the archive, which you don't want. So I ended up using a Copy Files phase and setting Skip Install to YES while pointing the Header Search Paths in tha parent project to BUILT_PRODUCTS_DIR.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top