Building libCURL for iOS 4.2

I recently had to rebuild libCURL for iOS4.2 because I was getting crashes in the simulator related to libCURL which were not present in iOS4.1:

Detected an attempt to call a symbol in system libraries that is not present on the iPhone:
close$UNIX2003 called from function Curl_getaddrinfo in image TripBoss.
If you are encountering this problem running a simulator binary within gdb, make sure you 'set start-with-shell off' first.
Program received signal: “SIGABRT”.

Unfortunately, adding "set start-with-shell 0" to ~/.gdbinit did not rectify the problem and as this forum post eludes to, the library needed to be rebuild without the $UNIX2003 symbol decoration.

So, here is the procedure I am using to build libCURL without SSL (since SSL may require export restrictions). Thanks to Silviu Caragea and Sam le Pirate for leading the way.

Download CURL source from:

tar -xvzf curl-7.21.2.tar.gz
cd curl-7.21.2
export CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-gcc-4.0.1
export CFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk"
export LDFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -Wl,-syslibroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk"
export CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp
./configure --disable-shared --without-ssl --without-libssh2 --without-ca-bundle --without-ldap --disable-ldap --host=arm-apple-darwin10

By configuring with isysroot and syslibroot set the correct SDK, the CURL_SIZEOF_LONG and SIZEOF_LONG will get set to the correct value (4).

In Xcode, choose File->New Project->iOS->Library->Cocoa Touch Static Library.
Add->Existing Files (select curl's "src" folder)
Add->Existing Files (select curl's "lib" folder)
Remove "src/macos" folder from project. (Delete->Delete references)
Unselect Makefile and checkboxes for target.

In “Build” tab search for OTHER_CFLAGS and add the following options:

-DHAVE_CONFIG_H -I/ca/dev/code/lib/curl/curl-latest/include -I/ca/dev/code/lib/curl/curl-latest/lib

Replace /ca/dev/code/lib/curl/curl-latest with the path at which you untarred the CURL source.
Build both Simulator/Release and Device/Release.

To make a universal library for both the simulator and the device, execute lipo from the command line of the Xcode project folder:

lipo -create build/Release-iphonesimulator/libcurl.a build/Release-iphoneos/libcurl.a -output libcurl.a

The last step is to add libCURL to your app by right-clicking (or option-clicking) Frameworks->Add->Add Existing Frameworks...->Other and choosing the libCURL.a file created by lipo.