» Building PCRE static lib for the iPhone

Building a static lib for the iphone is kind of tricky. I couldn't find much documentation on the process, so here is the script I used to compile PCRE for the iphone. I'm using the 2.2 SDK in these examples... if you are using something different don't forget to change the path.

#!/bin/bash

# This script will compile a PCRE static lib for the device and simulator

cd pcre

# Compile a version for the device...

CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp \
AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar \
./configure --disable-shared --host=arm-apple-darwin --disable-cpp \
CFLAGS="-arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk"

make

mv .libs/libpcre.a .libs/libpcre_device.a

# Compile a version for the simulator...
CC=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc \
CPP=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/cpp \
AR=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar \
./configure --disable-shared --disable-cpp \
CFLAGS="-isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.sdk"

make

mv .libs/libpcre.a .libs/libpcre_simulator.a

# Combine the two libs into one lib
lipo -create .libs/libpcre_simulator.a .libs/libpcre_device.a -output  .libs/libpcre.a

cp .libs/libpcre.a YOU_PROJECT_DIR
cp pcre.h YOU_PROJECT_DIR

Then all you have to do is add libpcre.a and pcre.h to your project and you'll be set for both simulator and device builds.

User Comments

Recent Posts

  • Interactive console for iOS! - August 20, 2010
  • Archive

    • Letter to Steve Jobs - April 11, 2010
    • Wax talks to Twitter - October 20, 2009
    • How does iPhone Wax work? - October 19, 2009
    • Setting up iPhone Wax - October 18, 2009
    • Ruby (tinyrb) on iPhone - May 03, 2009
    • Building PCRE static lib for the iPhone - May 02, 2009
    • Amazon EC2 + Chef = Mmmmm - March 29, 2009
    • Objective-c key paths - February 13, 2009
    • POW! - December 26, 2008
    • Abusing Ruby's question mark methods. - November 28, 2008
    • Git hooks make me giddy - November 07, 2008
    • Ruby Equality! equal? eql? == and === - October 26, 2008
    • Ruby, Rails and Google Sitemaps - October 20, 2008
    • Projects

      • Wax Obj-C to Lua bridge for iPhone.
      • Pow a Ruby library for making file & directory manipulation easy.
      • MiniMagick a tiny RMagick replacement.