libcurl for iOS 7.39.0

Here's a precompiled binary of libcurl, its headers, and a sample app for iOS developers. (Since the command line of iOS is only available on jailbroken devices, it didn't make much sense to offer the command line tool here.) Separate libraries for the device and simulator are included, as are the headers.

libcurl is a developer library that works similarly to Apple's NSURLConnection URL loader, but offers many more protocols and has many more options. And it's also available for Android and QNX and many other platforms as well. Any version of Xcode with an iOS SDK is necessary to get it to work. All releases of Xcode 4.0 and later have come with iOS SDKs.

The sample app, iOScURL, shows how to do some simple operations, such as downloading data from a server, as well as more complicated operations, such as sending WebDAV commands to a WebDAV server.

If you're looking for documentation for libcurl, you can read it online here, or you can read the documentation for specific functions by reading the man pages for the functions in Xcode or your favorite man page reader. OS X comes with libcurl, so the man pages are already installed on your Mac.

How to use the headers & libraries in your own project:

  1. Copy the "curl" directory, which includes the headers, into a place in your project's header search paths, such as the root directory of your project's source code.
  2. Copy the static library from the sample code into your project. Where it is placed is up to you.
  3. You must link the project to the Security framework and the libz library. I also recommend you link the project to the CFNetwork library so you can read the device's proxy settings and use them to initialize proxy support in libcurl.
  4. If you did all of the above and it's still not linking, you may need to run ranlib on the archives once in order to update their TOCs.

What features are included in these pre-compiled binaries:

What features aren't included:

The library is built for armv7, armv7s, arm64, i386 (for the simulator), and x86_64 (also for the simulator). Therefore, it requires an iPhone 3GS or later, or iPod touch 3 or later, or any iPad. Both libraries are compiled against the iOS 7 SDK, but were built with a deployment target of 4.3. SSL and TLS require iOS 5 or later, since Secure Transport did not become public API until iOS 5 was released.

As far as I know, neither binary includes any actual cryptography or digest-generating code. It uses the Security framework and CommonCrypto library for all of its cryptography and digest-generation needs. And CommonCrypto is a part of the standard C library on iOS and OS X.

If you need support, then please ask on the curl-library mailing list, where libcurl users or developers can help you.

How to build libcurl (or any other project that uses GNU Autotools) for iOS

I've had some people ask me how I built libcurl for iOS. Unfortunately a lot of the information currently on the Web on how to build projects that use GNU Autotools for build configuration on iOS is obsolete, because the compilers, paths, and build architectures for iOS binaries have all been changed in newer versions of Xcode.

First, you need to have both Xcode and the command line developer tools installed. You can get both by running xcode-select --install in the command line while logged into the GUI. Then just follow the instructions in the window that appears on the screen.

Here is what I use on Xcode 5.1.x to build for the device:

$ export IPHONEOS_DEPLOYMENT_TARGET="4.3"
$ export CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
$ export CFLAGS="-arch [ARCH] -pipe -Os -gdwarf-2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk"
$ export LDFLAGS="-arch [ARCH] -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk"
$ ./configure --disable-shared --enable-static --host="[ARCH]-apple-darwin" --prefix=[PREFIX] [OTHER_BUILD_FLAGS]
$ make -j `sysctl -n hw.logicalcpu_max`

...where you substitute:

Note that you don't need to run "make install" if you don't want to do that. You can just run a regular build, and then copy the built library from out of the ./lib/.libs folder. (The folder location varies from project to project, but that's where the curl project places its built products.)

After running make, if you're getting the build error "We can't compile without socket() support!" or some other bizarre error, then your Mac's command line tools installation is either broken or obsolete. Try running xcode-select --install again and choose to re-install the command line tools, then try running configure again after it's done.

Building for the simulator is a little bit different:

$ export IPHONEOS_DEPLOYMENT_TARGET="4.3"
$ export CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
$ export CFLAGS="-arch [ARCH] -pipe -Os -gdwarf-2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk"
$ export CPPFLAGS="-D__IPHONE_OS_VERSION_MIN_REQUIRED=${IPHONEOS_DEPLOYMENT_TARGET%%.*}0000"
$ export LDFLAGS="-arch [ARCH] -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk"
$ ./configure --disable-shared --enable-static --host="[ARCH]-apple-darwin" --prefix=[PREFIX] [OTHER_BUILD_FLAGS]
$ make -j `sysctl -n hw.logicalcpu_max`

Note the CPPFLAGS variable above. If you don't set this as described, then the compiler will think you're building for OS X instead of iOS, and it'll use the incorrect availability macros when reading the SDK headers (oops!).

Now, to combine them together, you need to copy each built library out of the build. I use the Desktop folder, which makes the temporary files easy to delete, but you can use the folder of your choice:

$ cp lib/.libs/libcurl.a ~/Desktop/libcurl-[ARCH].a
$ make clean

And finally, when all architectures are built, you combine them using lipo, like this:

$ cd ~/Desktop
$ lipo -create -output libcurl.a libcurl*

There's one more thing: If you're using a newer version of Xcode than 5.1, then you will also need to change the iOS SDK version in the path to whichever version of the SDK came with your version of Xcode.

Download libcurl for iOS 7.39.0

Back to Nick's Software Page