期盼死亡的小丑 发表于 2015-12-30 09:59:58

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

  转载请注明出处
  在进行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.14.tar.gz
cd automake-1.14
./configure --prefix=/usr/local
make
sudo make install

4)安装libtool
http://www.gnu.org/software/libtool/
tar xzvf libtool-2.4.2.tar.gz
cd libtool-2.4.2
./configure --prefix=/usr/local
make
sudo make install
  
  5)下载libcurl源码,运行libcurl初始化脚本
  git clone https://github.com/bagder/curl.git
  cd curl
  ./buildconf
  
  6)编译simulator版本,首先需要设置诸多编译环境,本人mac环境是xcode 6.4, sdk是8.4为例
export IPHONEOS_DEPLOYMENT_TARGET="8.4"
export CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
export CFLAGS="-arch i386 -pipe -Os -gdwarf-2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk"
export LDFLAGS="-arch i386 –isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk"
./configure --disable-shared --enable-static --host="i386-apple-darwin" --prefix=/usr/local --with-darwinssl --enable-threaded-resolver
make -j `sysctl -n hw.logicalcpu_max
cp lib/.libs/libcurl.a ~/Desktop/libcurl-i386.a
  make clean
  
  7)编译arm版本稍有不同
  export IPHONEOS_DEPLOYMENT_TARGET="8.4"
  $ export CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
  $ export CFLAGS="-arch -pipe -Os -gdwarf-2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk"
  $ export LDFLAGS="-arch -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk"
  $ ./configure --disable-shared --enable-static --host="-apple-darwin" --prefix=/usr/local --with-darwinssl --enable-threaded-resolver
  $ make -j `sysctl -n hw.logicalcpu_max`
cp lib/.libs/libcurl.a ~/Desktop/libcurl-.a
  make clean
  此处特别注意代表armv7,armvs7和arm64,但是-apple-darwin这里却不存在arm64-apple-darwin,需要改成arm-apple-darwin即可config通过。
  
  8)合并libcurl
  cd ~/Desktop
  $ lipo -create -output libcurl.a libcurl*
页: [1]
查看完整版本: Mac OS X环境下源代码编译libcurl