为iOS编译arm64和x86_64架构的Libical

6

我花了一些时间为iOS(设备和模拟器)编译LibiCal的arm64和x86_64架构版本,以便让其他人也可以受益。以下是我编译LibiCal-1.0所遵循的步骤。我从下面的链接中获取了代码:

编译libical

并进行了一些修改以适应Xcode 5.1。

1)从以下URL下载LibiCal

http://sourceforge.net/projects/freeassociation/

解压并进入libCal-1.0文件夹。然后运行

./bootstrap

(需要从http://www.jattcode.com/installing-autoconf-automake-libtool-on-mac-osx-mountain-lion/下载make工具)

使用下面的脚本

#!/bin/sh

# SEE: http://www.smallsharptools.com/downloads/libical/

PATH="`xcode-select -print-path`/usr/bin:/usr/bin:/bin"

# set the prefix
PREFIX=${HOME}/Library/libical
OUTPUTDIR=../libical-build

export ARCH=arm64

# Select the desired iPhone SDK
export SDKVER="7.1"
export DEVROOT=`xcode-select --print-path`
export  SDKROOT=$DEVROOT/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk
export IOSROOT=$DEVROOT/Platforms/iPhoneOS.platform

# Includes
# find $DEVROOT -type d -name include|grep -i iphone|grep -i arm-apple-darwin|grep -vi    install-tools|grep -vi simulator

# $SDKROOT/usr/include
# $DEVROOT/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/lib/gcc/arm-apple-darwin10/4.2.1/include

if [ ! -d $DEVROOT ]
then
        echo "Developer Root not found! - $DEVROOT"
        exit
fi

echo "DEVROOT = $DEVROOT"

if [ ! -d $SDKROOT ]
then
        echo "SDK Root not found! - $SDKROOT"
        exit
fi

echo "SDKROOT = $SDKROOT"

if [ ! -d $IOSROOT ]
then
        echo "iOS Root not found! - $IOSROOT"
        exit
fi

echo "IOSROOT = $IOSROOT"

# finding ld
# find $DEVROOT -type f -name ld|grep -i iphone

# Set up relevant environment variables 
export CPPFLAGS="-arch $ARCH -I$SDKROOT/usr/include -I$IOSROOT/Developer/usr/llvm-gcc-4.2/lib/gcc/arm-apple-darwin10/4.2.1/include"
export CFLAGS="$CPPFLAGS -pipe -no-cpp-precomp -isysroot $SDKROOT"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-L$SDKROOT/usr/lib/ -arch $ARCH"

export CLANG=$DEVROOT/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang

#export CC=$IOSROOT/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2
#export CXX=$IOSROOT/Developer/usr/bin/arm-apple-darwin10-llvm-g++-4.2

export CC=$CLANG
export CXX=$CLANG
export LD=$IOSROOT/Developer/usr/bin/ld
export AR=$IOSROOT/Developer/usr/bin/ar 
export AS=$IOSROOT/Developer/usr/bin/as 
export LIBTOOL=$IOSROOT/usr/bin/libtool 
export STRIP=$IOSROOT/Developer/usr/bin/strip 
export RANLIB=$IOSROOT/Developer/usr/bin/ranlib

HOST=arm-apple-darwin10

if [ ! -f $CC ]
then
        echo "C Compiler not found! - $CC"
        exit
fi

if [ ! -f $CXX ]
then
        echo "C++ Compiler not found! - $CXX"
        exit
fi

if [ ! -f $LD ]
then
        echo "Linker not found! - $LD"
        exit
fi

if [ -d $OUTPUTDIR/$ARCH ]
then 
       rm -rf $OUTPUTDIR/$ARCH
fi

find . -name \*.a -exec rm {} \;
make clean

./configure --prefix=$PREFIX --disable-dependency-tracking --host $HOST CXX=$CXX CC=$CC LD=$LD AR=$AR AS=$AS LIBTOOL=$LIBTOOL STRIP=$STRIP RANLIB=$RANLIB

make -j4

# copy the files to the arch folder

mkdir -p $OUTPUTDIR
mkdir -p $OUTPUTDIR/$ARCH

cp `find . -name \*.a` $OUTPUTDIR/$ARCH/

xcrun -sdk iphoneos lipo -info $OUTPUTDIR/$ARCH/*.a

echo $ARCH DONE

echo "See $OUTPUTDIR"

修改第11行"export ARCH=arm64"以获得所需的架构,例如arm64、armv7、armv7s。

这将在../libical-build文件夹中创建所需架构的二进制文件。

为x86_64构建。

使用以下命令运行x86_64的构建。

tar -xovf libical-1.0.tar
cd libical-1.0
./bootstrap
./configure
make

这应该在src/libical/.libs/文件夹中创建libical.a。

创建一个fat库

使用以下命令构建fat库。(请使用适当的lipo命令)。

export DEVROT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/lip

$DEVROOT/usr/bin/lipo 
    -arch arm64 $OUTPUTDIR/armv6/libical.a 
    -arch i386 $OUTPUTDIR/i386/libical_Simulator.a 
    -arch armv7 $OUTPUTDIR/x86_64/libical.a 
    -arch armv7s $OUTPUTDIR/x86_64/libical.a 
    -arch x86_64 $OUTPUTDIR/x86_64/libical.a 
    -create -output $OUTPUTDIR/libical_fat_universal.a

请设置适当的OUTPUTDIR环境变量。
我希望以上内容能帮助那些想快速为iOS构建Libical的人。

iOS和x86_64?那是什么设备? - trojanfoe
嗨,Girish,这非常有用 - 谢谢您发布这个! - user1514989
一个问题 - 如何获取i386 libical.a?对我来说,编译停止了,显示“致命错误:发出太多错误,现在停止[-ferror-limit=]”。该文件的名称也不同。有什么步骤吗? - user1514989
@trojanfoe 很想看看您使用 xcrun 的答案。 - ahalls
@user1514989 我似乎无法构建 i386 或 x86_64 库,然后将其馈入 lipo 命令以创建一个完整的 fat 库。有人能帮忙吗? - ahalls
显示剩余3条评论
2个回答

3
我找到了解决这个问题的方法。我主要做的是添加以下开关。
-mios-simulator-version-min=7.0

这是我目前的脚本版本:

 #!/bin/sh

set -o xtrace

# SEE: http://www.smallsharptools.com/downloads/libical/

PATH="`xcode-select -print-path`/usr/bin:/usr/bin:/bin"


if [ ! -n "$ARCH" ]; then
    export ARCH=armv7
fi


# Select the desired iPhone SDK
export SDKVER="7.1"
export DEVROOT=`xcode-select --print-path`

if [ "i386" = $ARCH ] || [ "x86_64" = $ARCH ]; then
    export SDKROOT=$DEVROOT/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDKVER}.sdk
    export MIOS="-mios-simulator-version-min=7.0"
else
    export SDKROOT=$DEVROOT/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk
    export MIOS=""
fi;
export IOSROOT=$DEVROOT/Platforms/iPhoneOS.platform



if [ ! -d $DEVROOT ]
then
        echo "Developer Root not found! - $DEVROOT"
        exit 1
fi

echo "DEVROOT = $DEVROOT"

if [ ! -d $SDKROOT ]
then
        echo "SDK Root not found! - $SDKROOT"
        exit 1
fi

echo "SDKROOT = $SDKROOT"

if [ ! -d $IOSROOT ]
then
        echo "iOS Root not found! - $IOSROOT"
        exit 1
fi

echo "IOSROOT = $IOSROOT"

# Set up relevant environment variables 
export CPPFLAGS="-arch $ARCH -I$SDKROOT/usr/include $MIOS --debug"
export CFLAGS="$CPPFLAGS -pipe -no-cpp-precomp -isysroot $SDKROOT "
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-L$SDKROOT/usr/lib/ -arch $ARCH"

export CLANG=$DEVROOT/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang


export CC=$CLANG
export CXX=$CLANG
export LD=$IOSROOT/Developer/usr/bin/ld
export AR=$IOSROOT/Developer/usr/bin/ar 
export AS=$IOSROOT/Developer/usr/bin/as 
export LIBTOOL=$IOSROOT/usr/bin/libtool 
export STRIP=$IOSROOT/Developer/usr/bin/strip 
export RANLIB=$IOSROOT/Developer/usr/bin/ranlib
export LIPO="xcrun -sdk iphoneos lipo"
export HOST=arm-apple-darwin10


if [ ! -f $CC ]
then
        echo "C Compiler not found! - $CC"
        exit
fi

if [ ! -f $CXX ]
then
        echo "C++ Compiler not found! - $CXX"
        exit
fi

if [ ! -f $LD ]
then
        echo "Linker not found! - $LD"
        exit
fi

if [ -d $OUTPUT_DIR/$ARCH ]
then 
       rm -rf $OUTPUT_DIR/$ARCH
fi

find ./src -name \*.a -exec rm {} \;
make clean


./configure --prefix="$OUTPUT_DIR" --disable-dependency-tracking --host $HOST CXX=$CXX CC=$CC LD=$LD AR=$AR AS=$AS LIBTOOL=$LIBTOOL STRIP=$STRIP RANLIB=$RANLIB

make -j4

# copy the files to the arch folder

mkdir -p $OUTPUT_DIR
mkdir -p $OUTPUT_DIR/$ARCH

cp `find . -name \*.a` $OUTPUT_DIR/$ARCH/
cp config.log $OUTPUT_DIR/$ARCH/config.log

$LIPO -info $OUTPUT_DIR/$ARCH/*.a

echo $ARCH DONE

echo "See $OUTPUT_DIR"

我已经开始为这个库构建Objective C包装器,您可以在https://github.com/ahalls/XbICalendar上看到进展情况。该项目需要一些眼球提出建议,甚至需要一些帮助。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接