Tutorial: Open Source on iOS (Part 3): Creating Pseudo-Frameworks

On Mac OS X frameworks provide a convenient way to package the dynamic libraries and header files into a single directory structure making it easier to include them in Xcode projects. Apple does not allow dynamic libraries (other than ones they provide) to be used with iOS so it may appear the third-party frameworks are not possible, however it is possible to create a pseudo-framework using a static library giving many of benefits of a real framework. In this tutorial you will combine the static libraries you created in the previous tutorial in a single pseudo-framework that will contain binaries for both the device and simulator.

Creating Ogg.framework

First ensure that you are in the directory where you built libogg.

Now make a directory to hold the framework files.

Copy the header file from one of the install directories to the Headers sub-directory within the framework.
[code]
cp -R install-iPhoneSimulator-i386/include/ogg Ogg.framework/Headers
[/code]
Finally create a fat static library in the framework directory with the same name as the framework
[code]
lipo -create -output Ogg.framework/Ogg \
-arch i386 install-iPhoneSimulator-i386/lib/libogg.a \
-arch armv7 install-iPhoneOS-armv7/lib/libogg.a
[/code]

A script for creating frameworks idz_fw

The steps in the above section can be generalized and made into a script. Using a text editor create the file $IDZ_BUILD_ROOT/bin/idz_fw with the following contents:

Don’t forget to make it executable.

The arguments to this script are the framework name without the .framework extension, the library name and directory containing the include files to be copied to Headers. The script assumes the build naming convention used in the previous tutorial.

Using this script all the steps of the previous section can accomplished with the command:

The Ogg.framework is now ready to use, however without a codec it is not all that interesting. In the next tutorial you will use the scripts developed so far to compile libvorbis an open source audio codec.


About idz

A professional software engineer dabbling in iOS app development.
This entry was posted in Tutorial. Bookmark the permalink.

Leave a Reply