Mac OS X环境下源代码编译libcurl

转载请注明出处

(2016.05.25更新,增加socket编译错误修改)

(2016.02.25更新,新增bitcode编译,新增x86_64编译)

在进行libcurl的源码编译之中,参照官方文档和google搜索出来的总是编译失败,索性根据提示的失败一步一步查出原因,说白了,就是OS X缺少gnu的几个工具,还需要初始化config才行,libcurl官方根本没提及,ok,那就自己搞定。

首先,需要安装autoconf和automake工具

1)安装m4

http://www.gnu.org/software/m4/

tar -xzvf m4-1.4.17.tar.gz

cd m4-1.4.17

./configure --prefix=/usr/local

make

sudo make install

 

2)安装autoconf

http://www.gnu.org/software/autoconf/

tar -xzvf autoconf-2.69.tar.gz

cd autoconf-2.69

./configure --prefix=/usr/local

make

sudo make install

 

3)安装automake

http://www.gnu.org/software/automake/

tar xzvf automake-1.15.tar.gz

cd automake-1.15

./configure --prefix=/usr/local

make

sudo make install

 

4)安装libtool

http://www.gnu.org/software/libtool/

tar xzvf libtool-2.4.6.tar.gz

cd libtool-2.4.6

./configure --prefix=/usr/local

make

sudo make install

 

5)下载libcurl源码,运行libcurl初始化脚本

git clone https://github.com/bagder/curl.git

cd curl

./buildconf

 

6) 通过macport安装socket

port install socket(否则会报"We can't compile without socket() support!"错误)

 

7)编译simulator版本,首先需要设置诸多编译环境,本人mac环境是xcode 7.3.1, sdk是9.3为例

export IPHONEOS_DEPLOYMENT_TARGET="10.3"

export CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"

export CFLAGS="-arch [ARCH] -pipe -Os -gdwarf-2 -fembed-bitcode -miphoneos-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk"

./configure --disable-shared --enable-static --host="[ARCH]-apple-darwin" --prefix=/usr/local --with-darwinssl --enable-threaded-resolver

make -j `sysctl -n hw.logicalcpu_max`

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

make clean

此处特别注意[ARCH]代表i386和x86_64

 

8)编译arm版本稍有不同

export IPHONEOS_DEPLOYMENT_TARGET="10.3"

export CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"

export CFLAGS="-arch [ARCH] -pipe -Os -gdwarf-2 -fembed-bitcode -miphoneos-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk"

./configure --disable-shared --enable-static --host="[ARCH]-apple-darwin" --prefix=/usr/local --with-darwinssl --enable-threaded-resolver

make -j `sysctl -n hw.logicalcpu_max`

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

make clean

此处特别注意[ARCH]代表armv7,armvs7和arm64,但是[ARCH]-apple-darwin这里却不存在arm64-apple-darwin,需要改成arm-apple-darwin即可config通过。

 

8)合并libcurl

cd ~/Desktop

lipo -create -output libcurl.a libcurl*

转载于:https://www.cnblogs.com/jialan/p/4639249.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值