dimitrios dimitrios - 15 days ago 8
iOS Question

Static Library public headers are not copied to Build/Products folder

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.

Answer

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

Comments