您好,登錄后才能下訂單哦!
折騰了4天,終于在xcode上完成protobuf2.5.0的交叉編譯,希望與我遇到相同問題的同學不在糾結。分享如下:
步驟一:部署protoc.exe
1)sudo su ---進入管理模式
//以下操作切換至protobuf文件夾下
2)./configure
3)make
4)make check
5)make install
此時可以查看protobuf文件夾下面的makefile文件,可以查看-build表示的本機環境以及-host表示的編譯庫的運行環境
我本地的-build=x86_64-apple-darwin12.3.0
-host=x86_64-apple-darwin12.3.0
(這兩個參數在后續配置腳本需要用到,與后面腳步的i686-apple-darwin12.3.0以及arm-apple-darwin12.3.0后綴“arm-apple-darwin12.3.0”保持一致)
6)make distclean清理已生成的makefile,為交叉編譯配置新makefile做準備
步驟二:配置交叉編譯
1)執行腳本ios-build.sh,腳本內容如下:
configure_for_platform() {
export PLATFORM=$1
#export PLATFORM=iPhoneOS
echo "Platform is ${PLATFORM}"
if [ "$PLATFORM" == "iPhoneSimulator" ]; then
export ARCHITECTURE=i386
export ARCH=i686-apple-darwin12.3.0
fi
if [ "$PLATFORM" == "iPhoneOS" ]; then
export ARCHITECTURE=$2
export ARCH=arm-apple-darwin12.3.0
fi
export ARCH_PREFIX=$ARCH-
export SDKVER="6.1" #sdk版本號必須正確
export DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/${PLATFORM}.platform/Developer
export SDKROOT="$DEVROOT/SDKs/${PLATFORM}$SDKVER.sdk"
export PKG_CONFIG_PATH="$SDKROOT/usr/lib/pkgconfig:$DEVROOT/usr/lib/pkgconfig"
export AS="$DEVROOT/usr/bin/as"
export ASCPP="$DEVROOT/usr/bin/as"
export AR="$DEVROOT/usr/bin/ar"
export RANLIB="$DEVROOT/usr/bin/ranlib"
#export CPP="$DEVROOT/usr/bin/c++"
#export CXXCPP="$DEVROOT/usr/bin/c++"
export CC="$DEVROOT/usr/bin/gcc"
export CXX="$DEVROOT/usr/bin/g++"
export LD="$DEVROOT/usr/bin/ld"
export STRIP="$DEVROOT/usr/bin/strip"
export LIBRARY_PATH="$SDKROOT/usr/lib"
export CPPFLAGS=""
#export CFLAGS="-arch armv7 -fmessage-length=0 -pipe -fpascal-strings -miphoneos-version-min=4.0 -isysroot=$SDKROOT -I$SDKROOT/usr/include -I$SDKROOT/usr/include/c++/4.2.1/"
export CFLAGS="-arch ${ARCHITECTURE} -fmessage-length=0 -pipe -fpascal-strings -miphoneos-version-min=4.0 -isysroot=$SDKROOT -I$SDKROOT/usr/include -I$SDKROOT/usr/include/c++/4.2.1/"
export CXXFLAGS="$CFLAGS"
#export LDFLAGS="-isysroot='$SDKROOT' -L$SDKROOT/usr/lib/system -L$SDKROOT/usr/lib/"
export LDFLAGS="-arch ${ARCHITECTURE} -isysroot='$SDKROOT' -L$SDKROOT/usr/lib/system -L$SDKROOT/usr/lib/"
./configure --host=${ARCH} --with-protoc=protoc --enable-static --disable-shared
}
mkdir ios-build
#build for iPhoneSimulator
configure_for_platform iPhoneSimulator
make clean
make
cp src/.libs/libprotobuf-lite.a ios-build/libprotobuf-lite-i386.a
#提取完整版本(i386)
cp src/.libs/libprotobuf.a ios-build/libprotobuf-i386.a
#build for iPhoneOS armv7
configure_for_platform iPhoneOS armv7
make clean
make
cp src/.libs/libprotobuf-lite.a ios-build/libprotobuf-lite-armv7.a
#提取完整版本(armv7)
cp src/.libs/libprotobuf.a ios-build/libprotobuf-armv7.a
#build for iPhoneOS armv7s
configure_for_platform iPhoneOS armv7s
make clean
make
cp src/.libs/libprotobuf-lite.a ios-build/libprotobuf-lite-armv7s.a
#提取完整版本(armv7s)
cp src/.libs/libprotobuf.a ios-build/libprotobuf-armv7s.a
make clean
#cerate a fat library containing all achitectures in libprotobuf-lite.a
xcrun -sdk iphoneos lipo -arch armv7 ios-build/libprotobuf-lite-armv7.a -arch armv7s ios-build/libprotobuf-lite-armv7s.a -arch i386 ios-build/libprotobuf-lite-i386.a -create -output ios-build/libprotobuf-lite.a
#合并三個完整版本(libprotobuf.a)
xcrun -sdk iphoneos lipo -arch armv7 ios-build/libprotobuf-armv7.a -arch armv7s ios-build/libprotobuf-armv7s.a -arch i386 ios-build/libprotobuf-i386.a -create -output ios-build/libprotobuf.a
2)將打包生成的libprotobuf-lite.a和libprotobuf.a復制至工程下進行編譯,可以編譯protobuf在xcode上的模擬器版本和真機版本,完成交叉編譯。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。