ios - 为 arm64 和 x86_64 为 iOS 编译 Libical

标签 ios arm64 libical

我花了一些时间为 arm64 编译 LibiCal 和为 iOS(设备和模拟器)编译 x86_64 架构。认为它可能对其他人有用。这是我编译 LibiCal-1.0 所遵循的步骤。我从下面的链接中获取了代码

Compiling libical

并稍作修改以适应 Xcode 5.1

1) 从下面的 URL 下载 LibiCal

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

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

./引导

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

使用下面的脚本

#!/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 文件夹中为所需的架构创建 bin。

为 x86_64 构建。

使用以下命令为 x86_64 运行 get build。

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

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

创建脂肪库

使用下面的命令来构建 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 的人。

最佳答案

我已经找到了解决这个问题的方法。我做的主要事情是添加以下开关

-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我的项目可以使用一些眼球来提出建议甚至一些帮助。

关于ios - 为 arm64 和 x86_64 为 iOS 编译 Libical,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22986302/

相关文章:

iphone - 如何知道单元格的 ImageView 中是否有图像

ios - 在 iOS/swift 中获取当前屏幕的屏幕截图以进行共享

iOS:这个带有指针/箭头的框/菜单叫什么?

objective-c - Objective C - 字符转换为 NSString

libical的交叉编译

ios - 使用 CoreData 和数组填充 TableView 部分

arm - Objdump ARM aarch64 代码?

linux - 交叉编译中target的定义是什么

c - 为什么/如何在此签名溢出测试中gcc编译未定义的行为,以便它可以在x86上运行但不能在ARM64上运行?

iphone - iOS - libical/const char * - 内存使用