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.


libcurl objective c tutorial

hi, i'm new in IOS and ftp connection programming. Somebody tell me to use libcurl, but i'm sure, i dont know what to do. I really happy to see your post, because it's really hard to find some post about IOS and libcurl. Can you give me a tutorial or a link or maybe an example project about how to use libcurl with IOS?
I really appreciate for your answer (sorry for my bad English).

Thank You

a thousands error and warning when i build libcurl in Xcode

i have try to compile libcurl like all the steps that you share above,
but when i come to step for build libcurl in Xcode, the build process is failed and there are 14181 errors with so many warnings.
is there something wrong with me?

ld: library not found for -lssl collect2: ld returned 1 exit

Thank you for your tutorial, i have try all of them. I can build a libcurl.a from lipo command.
But now i have a problem. After i add that libcurl.a into framework, and then i try to include some curl headers such as :

#include "curl.h"
#include "easy.h"

and then i build my app project, xcode give me this error :
ld: library not found for -lssl collect2:
ld returned 1 exit status
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

why xcode give me that error?? can you help me??
Thank you

building libCurl for iOS 5


I am trying to install and build curl-7.21.3.....
System: Xcode 4.2, iOS SDK 5.0, Mac 10.6.8 platform.....
So, compiler llvm-gcc-4.2 is available because of new xcode version 4.2; that's why I do not have gcc-4.2
I would like to build with llvm-gcc-4.2 during cross compilation, and I am getting following error.

I will really appreciate for your hints. Thanks in advance!!!!

checking whether to enable maintainer-specific portions of Makefiles... no
checking whether to enable debug build options... no
checking whether to enable compiler optimizer... (assumed) yes
checking whether to enable strict compiler warnings... no
checking whether to enable compiler warnings as errors... no
checking whether to enable curl debug memory tracking... no
checking whether to enable c-ares for DNS lookups... no
checking for sed... /usr/bin/sed
checking for grep... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ar... /usr/bin/ar
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking curl version... 7.21.3
checking build system type... i386-apple-darwin10.8.0
checking host system type... i386-apple-darwin10.8.0
checking for style of include used by make... GNU
checking for gcc... Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc-4.2
checking whether the C compiler works... no
configure: error: in `/Users/shpatel/Desktop/dir/curl-7.21.3':
configure: error: C compiler cannot create executables
See `config.log' for more details

iOS 5

Can be very frustrating...for iOS 5 you now have to say:

export CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/bin/llvm-cpp-4.2

since they left out a symbolic link to cpp, use this and everything else should work great!

iOS5/XCode 4.2 ... still no love

Anyone yet having luck building this for iOS5/XCode 4.2?
I've just gone through the processes here, with no luck-- I too get the "this compiler can't make executables" error, and changing that export CPP line does nothing for me.

Has anyone built this for iOS5, and is willing to share the .a file?

configure: error: cannot find out size of long.

Here's my setup:

export CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2
export CFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk"
export CFLAGS='-Os'
export LDFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -Wl,-syslibroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk"
export CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-cpp-4.2

Any help would be appreciated;

Worked first time! No doubt

Worked first time! No doubt saved me ages, thanks v.much! Peace

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
1 + 8 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.