openFrameworks + iPhone libs

of_iphoneI’ve had a few days to test the libraries I cobbled together for using openFrameworks with iPhone and also received positive reports from some folks who tried out the Makefiles I provided to them, so here they are for anyone who’s willing to try them out. -please make these instructions better if you see fit-

Update (7.8.2009): Fixed some errant quote mark substitutions in the freetype configure line. Also corrected a tab formatting error in the freeimage makefile.

Ok, here goes. This is going to be a work-in-progress document. Of course, there are no promises with this and your mileage may vary…but it’s been working for me. Please report success (and trouble, hopefully with workarounds).

The basic “tutorial” I followed is on Memo Akten’s blog,

I’d highly suggest following Memo’s tutorial for setting up the development environment. However, there are three libraries that he mentions in his article that need to be built for the iPhone specifically: glu, freetype and freeimage. Although he mentions that they have been ported to iPhone I wasn’t able to locate binaries of the libraries, and went through the process of cross-compiling them myself. This post documents what I needed to do to accomplish that.

You’ll need to download the source for each of the libraries listed above, as well as a svn copy of open frameworks plus the ofxiPhone, ofxMultiTouch and ofxAccelerometer addons. I preferred to use ofx-dev which bundled this and many more addons. You also need the Apple Developer Tools including Xcode and the iPhone SDK.

GLU for iPhone:
The glu for iphone package builds painlessly. Build twice: once for the iPhone, once for the iPhone Simulator. Make sure to do a “make clean” before building the second version. The readme explains the make command. I copied the entire folder to ofx-dev/libs/gluiphone

The other two were more difficult for me. I’ve never cross-compiled, so perhaps that contributed to the trouble I had.

Here is the makefile that I came up with, based on the existing files and what I saw in the glu makefile. Copy the makefile listed below as “Makefile.iphone” alongside the others in the source directory, then run “make -f Makefile.iphone”. This should build both the iPhone and iPhone Simulator libraries into the “Dist” folder. Copy both files to ofx-dev/libs/freeimage/lib

# Configuration for iPhone OS, making static libs
# this will generate both iPhone (arm) and iPhoneSimulator (i686) libs

include Makefile.srcs

CFLAGS =  -g -O2 -Wall -Wmissing-prototypes -std=c99 -ffast-math -fno-strict-aliasing
CXXFLAGS =  -g -O2 -Wall -fno-strict-aliasing


PLATFORM_SIM = iPhoneSimulator

ARCH_SIM = i686
ARCH_PHONE = armv6

PLATFORM_SIM_DEVELOPER_BIN_DIR = /Developer/Platforms/$(PLATFORM_SIM).platform/Developer/usr/bin
PLATFORM_PHONE_DEVELOPER_BIN_DIR = /Developer/Platforms/$(PLATFORM_PHONE).platform/Developer/usr/bin


EXTRA_CFLAGS_SIM += -arch $(ARCH_SIM) -pipe -mdynamic-no-pic -fvisibility=hidden $(INCLUDE) -isysroot $(SDKROOT_SIM)
EXTRA_LDFLAGS_SIM += -arch $(ARCH_SIM) -isysroot $(SDKROOT_SIM) -Wl,-dead_strip

EXTRA_CFLAGS_PHONE += -arch $(ARCH_PHONE) -pipe -mdynamic-no-pic -fvisibility=hidden $(INCLUDE) -isysroot $(SDKROOT_PHONE)
EXTRA_LDFLAGS_PHONE += -arch $(ARCH_PHONE) -isysroot $(SDKROOT_PHONE) -Wl,-dead_strip



CXXFLAGS_SIM += $(EXTRA_CFLAGS_SIM) -fvisibility-inlines-hidden
LIBTOOL_SIM = /Developer/Platforms/$(PLATFORM_SIM).platform/Developer/usr/bin/libtool

CXXFLAGS_PHONE += $(EXTRA_CFLAGS_PHONE) -fvisibility-inlines-hidden
LIBTOOL_PHONE = /Developer/Platforms/$(PLATFORM_PHONE).platform/Developer/usr/bin/libtool

TARGET = freeimage
STATICLIB_SIM = lib$(TARGET)-iphonesimulator.a
HEADER = Source/FreeImage.h

.SUFFIXES: .o-i686 .o-arm
MODULES_ARM = $(SRCS:.c=.o-arm)
MODULES_ARM := $(MODULES_ARM:.cpp=.o-arm)
MODULES_i686 = $(SRCS:.c=.o-i686)
MODULES_i686 := $(MODULES_i686:.cpp=.o-i686)

default: all

all: dist

dist: FreeImage
	cp *.a Dist
	cp Source/FreeImage.h Dist


	$(LIBTOOL_SIM) -arch_only i686 -o $@ $(MODULES_i686)

	$(CC_SIM) $(CFLAGS_SIM) -c $< -o $@

	$(CXX_SIM) $(CXXFLAGS_SIM) -c $< -o $@

	$(LIBTOOL_PHONE) -arch_only armv6 -o $@ $(MODULES_ARM)

	$(CC_PHONE) $(CFLAGS_PHONE) -c $< -o $@

	$(CXX_PHONE) $(CXXFLAGS_PHONE) -c $< -o $@

	rm -f core Dist/*.* u2dtmp* $(MODULES_i686) $(MODULES_ARM) $(STATICLIB_SIM) $(STATICLIB_PHONE)

Their makefile situation got me all confused so i just passed command like configure arguments as necessary. This is pretty ugly. -Please make this better someone-

#building freetytpe for iphone
# for iPhone
./configure --prefix=/usr/local/iphone --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-gcc-4.0.1 CFLAGS="-arch armv6 -pipe -mdynamic-no-pic -std=c99 -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=2.0 -gdwarf-2 -mthumb -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/usr/include/libxml2 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk" CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar LDFLAGS="-arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk -Wl,-dead_strip -miphoneos-version-min=2.0"

# for iPhone simulator
./configure --prefix=/usr/local/iphone --enable-static=yes --enable-shared=no CC=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.0 CFLAGS="-arch i686 -pipe -mdynamic-no-pic -std=c99 -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -mmacosx-version-min=10.5  -I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.0.sdk/usr/include/ -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.0.sdk" CPP=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar LDFLAGS="-arch i686 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.0.sdk -Wl,-dead_strip -mmacosx-version-min=10.5"

Run one of the configure lines, then make. I got an error about “asm” being undefined…I think it was in include/freetype/config/ftconfig.h. Change “asm” to “__asm__” (that’s two underscores for both prefix and suffix). If it works then it drops the lib in a hidden dir: “./objs/.libs”.  Copy the static lib out of there and rename it as appropriate.  i’m using libfreetype-iphone.a and libfreetype-iphonesimulator.a. Run make clean and then run the other configure line and make again. There were some headers missing in from the freetype lib provided with ofx-dev that I noticed in the example ofxiPhone aps…so I copied the entire freetype folder to ofx-dev/libs/freetype-iphone. I put the libraries into freetype-iphone/lib so i could keep everything straight when setting up xcode.

Ok, I think this gets up to the point where we can set up xcode.

ofxiphone_xcodeCopy one of the ofxiPhone examples to ofx-dev/apps/dev and open it up in xcode. I used the Graphics example. There is some more explanation on Memo’s site about the project structure, but it was very similar to adding any other addons. However, I put gluiphone, freetype-iphone and freeimage into the libs>core>core libraries package in the xcode project. I’ve attached a screenshot to illustrate better than i can explain. (ofxVectorMath is there for the specific project i have open, is not required).


Go to menu Project>Edit Project Settings… and switch to the build tab. Set configuration to “All Configurations” and add in the library and header search paths as appropriate…just like setting up addons.

Set the Overview to Simulator – 2.0 | Debug and try to build. Make sure that all the appropriate libraries have been added to the Target. xcode seems to be able to pick the correct ones for the given architecture.


I initially got an error about a bad BOOL typedef in FreeImage.h:130 I changed it to typedef int8_t BOOL. In perhaps a separate issue, I don’t seem to be able to use the “Boolean” datatype, but can replace it with “bool” instead.

So, that’s what I did to get my system all set up to use openFrameworks with the iPhone. Feel free to let me know how it works out if you use this for yourself. Good luck!





5 responses to “openFrameworks + iPhone libs”

  1. Mauamau Avatar

    have you been able to compile freetype2 for the iphone? xcode is telling me that the resulting library has no armv6 arch intstruction when using almost the exact same configure as above.

  2. Robert Avatar

    No, I haven’t tried. Since openFrameworks 006 was released I haven’t tried compile the libs again.

  3. […] need to use an open-source library in an iPhone project. Recalling the earlier work necessary in compiling the libraries needed for openFrameworks I started looking for a more generic way to build for iPhone development. […]

  4. Jeff Crouse Avatar

    On lines 78, 81, 87, and 90 of your FreeImage makefile, there is a weird symbol after the -c that probably won’t make it through this submit form, but of course it should be a “less than” symbol rather than what it currently is. You will get an error something like:

    arm-apple-darwin10-g++-4.0.1: amp: No such file or directory
    arm-apple-darwin10-g++-4.0.1: no input files
    /bin/sh: lt: command not found
    /bin/sh: -o: command not found
    make: *** [Source/FreeImage/BitmapAccess.o-arm] Error 127

    Also, when compiling for iPhone OS 4.0, you must change

    GCC_VERSION = 4.0


    GCC_VERSION = 4.2

    Thanks for the file. It saved me tons of time!

  5. Robert Avatar

    Thanks for the catch…I’ll fix the makefile.


Leave a Reply