How to compile libcurl¶
This document describes how to compile libcurl for Android, iOS and windows. The difficulty to compile libcurl is the parameters for configuration.
You can download the source code from:
http://curl.haxx.se/download.html
The document bases on version 7.21.4.
1. Android¶
1.1 Configure¶
Place the curl source into external/curl/ in the Android source tree. Create a shell script configure.sh, and put it into external/curl/. The script content is:
#!/bin/sh
SDK_ROOT=/home/nudtzxm/android_sdk
export PATH="$SDK_ROOT/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin:$PATH"
./configure --host=arm-linux CC=arm-eabi-gcc \
CPPFLAGS="-I $SDK_ROOT/system/core/include
-I $SDK_ROOT/hardware/libhardware/include
-I $SDK_ROOT/hardware/libhardware_legacy/include
-I $SDK_ROOT/hardware/ril/include
-I $SDK_ROOT/dalvik/libnativehelper/include
-I $SDK_ROOT/frameworks/base/include
-I $SDK_ROOT/frameworks/base/opengl/include
-I $SDK_ROOT/external/skia/include
-I $SDK_ROOT/out/target/product/generic/obj/include
-I $SDK_ROOT/bionic/libc/arch-arm/include
-I $SDK_ROOT/bionic/libc/include
-I $SDK_ROOT/bionic/libstdc++/include
-I $SDK_ROOT/bionic/libc/kernel/common
-I $SDK_ROOT/bionic/libc/kernel/arch-arm
-I $SDK_ROOT/bionic/libm/include
-I $SDK_ROOT/bionic/libm/include/arch/arm
-I $SDK_ROOT/bionic/libthread_db/include
-I $SDK_ROOT/bionic/libc/kernel/common
-I $SDK_ROOT/bionic/libc/kernel/arch-arm
-I $SDK_ROOT/system/core/libcutils
-I $SDK_ROOT/out/target/product/generic/obj/STATIC_LIBRARIES/libcutils_intermediates
-I $SDK_ROOT/out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates
-I $SDK_ROOT/system/core/include/arch/linux-arm/
-include $SDK_ROOT/system/core/include/arch/linux-arm/AndroidConfig.h" \
CFLAGS="-nostdlib -fno-exceptions -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums
-Wno-multichar -msoft-float -march=armv5te -mtune=xscale -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__
-mthumb-interwork -DANDROID -fmessage-length=0
-W -Wall -Wno-unused -Winit-self -Wpointer-arith -Werror=return-type -Werror=non-virtual-dtor -Werror=address
-Werror=sequence-point -DSK_RELEASE -DNDEBUG -g -Wstrict-aliasing=2 -finline-functions
-fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop
-frename-registers -DNDEBUG -UDEBUG -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64" \
LIBS="-L$SDK_ROOT/out/target/product/generic/obj/lib
-L$SDK_ROOT/out/target/product/generic/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a -lc -lm -ldl
$SDK_ROOT/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/interwork/libgcc.a"
Goto the root of curl, and run the script:
1.2 Make¶
Goto the root of curl and make curl:
1.3 The parameters of configure¶
You may see the parameters of configuration are complex. How to set it? You should read the comments of curl/Android.mk.
2. iOS¶
I compile it as the article says:
http://www.creativealgorithms.com/blog/content/building-libcurl-ios-42
or
http://blog.sina.com.cn/s/blog_673975590100qjuh.html (chinese)
I change the parameters of configure, so the configure command is:
./configure --disable-shared --host=arm-apple-darwin10
3. Windows¶
Open the vc6curl.dsw and select "DLL Release" to build. You may find libcurl.dll and libcurl_imp.lib in the CURL_ROOT\lib\DLL-Release.
4. About the header files¶
The header files of curl/include can be only used after succesful configuration. And the header files are different on different platforms.