0

I want to create a iOS framework for a popular C library.

My Current Setup:

This is what I'm doing:

  1. Build the library for iOS and iPhone simulator architectures
  2. Combine the two archive .a files into a single fat library using lipo
  3. Use libtool -static -o to get the final library

By this stage I have a binary and a bunch of header files. In xcode:

  1. Drop the binary (from step 3) and ensure its linked under: Target > General > Framework and Libraries, and Target > Build Phases > Link Binary with Libraries

  2. I copy all the header files from the C library and place them under dir Dependencies/myClibrary/include/. The include dir contains a master header file myClibrary.h which includes a number of header files from ./abstract/*.h.

  3. At top level of the xcode project dir, I also create a module.map file with content:

module MyWrapperFramework [system] {
  header "Dependencies/myClibrary/include/myClibrary.h"
  export *
}
  1. Add all header files to xcode and for each header file, under Target Membership change value from project to public.

  2. Build

Testing the framework in an App

I am able to build the framework, with settings as mentioned above. However, when I want to test it in a test Objective C app, I import the framework and call functions related to the myClibrary. On building the app, I get the error:

'myClibrary/abstract/headername.h' file not found

The above error originates from myClibrary's master header file myClibrary.

Most of the tutorial that I could find deals with C libraries having a single header file. How can I create a iOS framework from a C library that contains nested header files?

In case, nested header files are not the main issue here, what am i doing wrong?

1 Answer 1

1

A framework's headers get installed in the Headers directory inside the .framework. The compiler knows enough magic that when you say #import <myClibrary/myClibrary.h> that it will start the search for myClibrary.h inside that Headers directory.

As a result, the default public header build rules are to copy all public .h files (no matter their position in the source tree) into that Headers directory. That directory should be set as the $PUBLIC_HEADERS_FOLDER_PATH variable during building.

It seems as though you need to install headers into different directories. You could simply set the value of the Public Headers Folder Path in build settings to be a subdirectory, which will then install all public headers there. You could then have a custom Copy Files build phase to install just the single, overall header into the original headers directory.

Or, you could just add just the headers which go into the root as public headers, then have a custom Copy Files phase for all the rest, which copy them into a custom subdirectory. I think if you choose "Wrapper" as the destination, that is the root of the framework, so if the subpath is "Headers/abstract" that should work (though I have not tested myself). If you need to have multiple subdirectories, you would need a custom Copy Files build phase for each one.

Or, of course, have a custom build script to copy the headers more manually, if that's easier than multiple build phases (say one that copies all files in the include directory to $PUBLIC_HEADERS_FOLDER_PATH but preserving the structure, if there are a lot of subdirectories).

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

1 Comment

hi Carl, sorry for late reply but yes you're right. I was setting header path incorrectly. Thanks :)

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.