首先设定环境变量:
真机:
export IPHONEOS_DEPLOYMENT_TARGET="4.3" export CC="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc-4.2" export CFLAGS="-arch armv7 -arch armv7s -pipe -Os -gdwarf-2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk" export LDFLAGS="-arch armv7 -arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk" ./configure --disable-shared --enable-static --disable-dependency-tracking --host="armv7-apple-darwin"
模拟器:
export IPHONEOS_DEPLOYMENT_TARGET="4.3" export CC="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2" export CFLAGS="-arch i386 -pipe -Os -gdwarf-2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk" export CPPFLAGS="-D__IPHONE_OS_VERSION_MIN_REQUIRED=${IPHONEOS_DEPLOYMENT_TARGET%%.*}0000" export LDFLAGS="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk" ./configure --disable-shared --enable-static --host="i386-apple-darwin"
编译:
a) 打开Xcode选择: File->New Project->iOS->Library->Cocoa Touch Static Library
添加文件:Add->Existing Files (选择curl中 "src"文件夹),Add->Existing Files (选择curl中 "lib"文件夹)
删除文件:从项目中删除 "src/macos" 文件夹(Delete->Delete references),并且去掉Makefile and Makefile.inc(共四个,src和lib中各两个)的”target”标志。(注意是在project中操作,不是在target中操作)
b) 打开“build”选项,查找OTHER_C_FLAGS设置下面信息
-DHAVE_CONFIG_H -I/ca/dev/code/lib/curl/curl-latest/include -I/ca/dev/code/lib/curl/curl-latest/lib
说明: /ca/dev/code/lib/curl/curl-latest就是刚才解压curl源代码的路径,在本机中是
-DHAVE_CONFIG_H -I/libcurl/curl/include -I/libcurl/curl/include/lib
然后直接利用Xcode编译就可以得到静态库文件。