protobuf 编译iOS,lib curl缺少行 x86_64的解决方法

来源:互联网 发布:java logger加日志 编辑:程序博客网 时间:2024/05/17 06:38

很多同学碰到libcurl这个问题都是因为protobuf大包iPhone的问题,各个团队的问题不一,也确实没唯一的解决方法,但核心问题还是第三方库和编译的问题。

protobuf这东西能不用就不用吧,跨平台这东西就算找谷歌的工程师来也真心不好弄

一直提少undefined symbols, 知道少了,你这个蠢货加上不就得了?

下面这里教你从头编译(没办法,几乎所有第三方库尼玛都得从头编译,立项之前先用膝盖想清楚,考虑下你的团队耗不耗得起这个时间)

(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(博主不需要这步,macOS自带)

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

 

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

export IPHONEOS_DEPLOYMENT_TARGET="9.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/iPhoneSimulator9.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="9.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/iPhoneOS9.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通过。


(编译是通过了,可以引用编译后的libcurl.a, 还是提示少了x86_64,法克)

 

8)合并libcurl

cd ~/Desktop

lipo -create -output libcurl.a libcurl*

0 0