實際開發(fā)過程中稀颁,遇到編譯iOS庫時,用到的第三方靜態(tài)庫不是iOS平臺的阶女,因此需要自己編譯靜態(tài)庫使用。下載第三庫的源碼吞瞪,然后解壓芍秆,之后把下面的腳本文件放在源碼解壓后的目錄,然后執(zhí)行這個腳本(這個腳本是在網(wǎng)上查找到的荆虱,做的很不錯)。最后生成會生成fat-libtool
和thin-libtool
目錄菜枷,fat-libtool
下面是所有iOS使用的平臺合成一個靜態(tài)庫,我使用的是這個目錄下靜態(tài)庫蚊锹。如果不需要每個平臺都集成牡昆,那么可以選擇thin-libtool
下面相應(yīng)平臺的靜態(tài)庫就可以了钻心。
#!/bin/sh
make distclean
CONFIGURE_FLAGS="--disable-shared --disable-frontend"
ARCHS="arm64 armv7s x86_64 i386 armv7"
# directories
# SOURCE是下載的第三方庫源碼包,解壓后的目錄痒给,可以把sh腳本放到這個目錄,source改為""
SOURCE=""
# FAT是所有指令集build后试吁,輸出的目錄,所有靜態(tài)庫被合并成一個靜態(tài)庫
FAT="fat-libtool"
# SCRATCH是下載源碼包余耽,解壓后的目錄
SCRATCH="./"
# must be an absolute path
# THIN 各自指令集build后輸出的靜態(tài)庫所在的目錄碟贾,每個指令集為一個靜態(tài)庫
THIN=`pwd`/"thin-libtool"
COMPILE="y"
LIPO="y"
if [ "$*" ]
then
if [ "$*" = "lipo" ]
then
# skip compile
COMPILE=
else
ARCHS="$*"
if [ $# -eq 1 ]
then
# skip lipo
LIPO=
fi
fi
fi
if [ "$COMPILE" ]
then
CWD=`pwd`
echo "$CWD/$SOURCE........."
for ARCH in $ARCHS
do
echo "building $ARCH..."
mkdir -p "$SCRATCH/$ARCH"
cd "$SCRATCH/$ARCH"
if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]
then
PLATFORM="iPhoneSimulator"
if [ "$ARCH" = "x86_64" ]
then
SIMULATOR="-mios-simulator-version-min=7.0"
HOST=x86_64-apple-darwin
else
SIMULATOR="-mios-simulator-version-min=5.0"
HOST=i386-apple-darwin
fi
else
PLATFORM="iPhoneOS"
SIMULATOR=
HOST=arm-apple-darwin
fi
XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
CC="xcrun -sdk $XCRUN_SDK clang -arch $ARCH"
#AS="$CWD/$SOURCE/extras/gas-preprocessor.pl $CC"
CFLAGS="-arch $ARCH $SIMULATOR"
CXXFLAGS="$CFLAGS"
LDFLAGS="$CFLAGS"
CC=$CC $CWD/$SOURCE/configure \
$CONFIGURE_FLAGS \
--host=$HOST \
--prefix="$THIN/$ARCH" \
CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
make -j3 install
cd $CWD
done
fi
if [ "$LIPO" ]
then
echo "building fat binaries..."
mkdir -p $FAT/lib
set - $ARCHS
CWD=`pwd`
cd $THIN/$1/lib
for LIB in *.a
do
cd $CWD
lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB
done
cd $CWD
cp -rf $THIN/$1/include $FAT
fi