【问题标题】:Compiling libical编译libical
【发布时间】:2011-11-04 02:32:58
【问题描述】:

我想编译 libical 并将其添加到我的 Xcode 项目中。

我已阅读 README 文件并在 Terminal.app 中运行以下命令:

./configure

./configure --prefix=/proj/local/

我是否应该将已编译的 .a 文件拖放到我的项目中?

【问题讨论】:

  • 这是为 iPhone 设计的,你不能只获取 .a 文件并使用它们。您需要交叉编译 iPhone 的代码,这可能需要您设置 CFLAGS 环境变量以使其编译 iPhone 兼容的代码。您还需要一个单独的版本才能在 iPhone 模拟器中使用。或者,您可以直接将源文件放入您的项目中。
  • 感谢回复,之前没用过CFLAGS,在readme文件中也找不到,请问有什么需要帮助的吗?
  • 好的,我想我已经成功编译了它,但是现在我在构建时收到以下错误:架构 i386 的未定义符号:“_bswap_32”,引用自:libical-static.a 中的 _decode (icaltz-util.o) ld:未找到架构 i386 collect2 的符号:ld 返回 1 个退出状态
  • 你正在为 i386 编译,即 x86 架构,实际的 iPhone 是 ARM 架构。您需要编译两个版本,一个用于 iPhone 模拟器,一个用于实际设备。将源文件集成到您的项目中或使其成为 iPhone 框架将是最简单的。
  • aah 好的,所以我有很多不同的库,i386 一个(如果我正在运行 lion,这甚至需要,不是用于旧处理器吗?)然后我有 x86_64 一个(我假设这是我对模拟器所需要的,我需要在目标有效架构中添加任何东西,比如 x86_64 吗?)最后一个是使用 ./configure -build=arm-apple-darwin9 编译的。 0.0d1 所以我假设这是设备上使用的手臂

标签: objective-c xcode frameworks build libical


【解决方案1】:

我是最初创建位于此处的那些构建脚本的人...

http://code.google.com/p/mwiphonesdk/source/browse/trunk/iMADE/PrepTasks/05+Event+Calendar/Packers+Schedule/libical/build+scripts/

我现在更新了脚本以使用最新的 iOS 6/Xcode 4.5 工具集。这是完全不同的,我已将其设置为使用 Clang。我尽我所能让这个脚本适应新的 SDK 版本。

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

脚本应放置在 libical 文件夹的根目录中并从那里运行。主脚本运行其他 2 个脚本来构建 armv7 和 armv7s 二进制文件,然后使用 xcrun 为 iphoneos 运行 lipo 将这些二进制文件组合成一个可用于 iOS 项目的胖二进制文件。

有一些重构可以很容易地完成,但我已经花了很多时间。我希望这可以帮助您使用该库。

#!/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=armv7

# Select the desired iPhone SDK
export SDKVER="6.0"
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/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool 
export STRIP=$IOSROOT/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/strip 
export RANLIB=$IOSROOT/Developer/Platforms/iPhoneOS.platform/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"

【讨论】:

  • 把arch改成i386知道失败的原因吗: /usr/bin/lipo: specifed architecture type (i386) for file (../libical-build/i386/libical .a) 不匹配它的cputype(12)和cpusubtype(11)(应该是cputype(7)和cpusubtype(3))?
  • 让它工作了,应该在 shell 脚本中选择 iPhoneSimulator${SDKVER}.sdk...
  • @Brennan,您是否更新了脚本以使用适用于 iOS 7 的 LLVM 5 编译 libical v1.0,包括 arm64 架构?有机会访问更新的脚本吗?提前谢谢你。
  • @MassimoCafaro 我一直在尝试为 iOS7 构建,但运气不佳。似乎最新的 libical 已转换为 cmake 进行构建,因此该脚本不再有效。不幸的是,我还不能使用 cmake 进行交叉编译 :(
  • 这个answer修改了iOS7的脚本。
【解决方案2】:

您所做的是为模拟器和手机编译库。

1.制作2个新目标,一个用于iphone,一个用于模拟器

2.编译

3.将它们与脂肪混合。

此链接将为您提供所有具体细节。 How to make universal static libraries

【讨论】:

    【解决方案3】:

    这个问题的其他答案对特定的 libical 没有帮助,因为它的配置脚本很挑剔。您需要拥有大量正确的环境变量。这些脚本已经把它们都弄清楚了。

    http://code.google.com/p/mwiphonesdk/source/browse/trunk/iMADE/PrepTasks/05+Event+Calendar/Packers+Schedule/libical/build+scripts/

    下载上述脚本,并调整 build_(platform).sh 以找到正确的编译器和 SDK 文件夹。这将根据您的目标以及您的 Xcode 开发人员工具的最新程度而改变。找到正确的值应该很容易,只需在相同的位置查找它们在系统上的名称即可。

    输出将是一个胖“.a”文件,其中包含模拟器和设备的二进制文件。

    在这些文件消失的情况下,我在下面收集了真正重要的一个(build_arm.sh,交叉编译):

    #!/bin/sh
    
    # Created by Robert Carlsen on 15.07.2009.
    # build an arm / i386 / x64 lib of standard linux project
    #
    # adopted from: http://latenitesoft.blogspot.com/2008/10/iphone-programming-tips-building-unix.html
    #
    # copied from: http://robertcarlsen.net/2009/07/15/cross-compiling-for-iphone-dev-884
    #
    # configured for libical
    #
    # Note:
    # To run with the iPhone the assembly just be a Universal binary (FAT) with i386 arch for the simulator
    # and arm arch for the iPhone hardware which has the arm processor.
    
    # set the prefix
    PREFIX=${HOME}/Library/libical
    OUTPUTDIR=../libical-build
    
    export ARCH=armv6
    export GCCARCH=arm-apple-darwin9
    export GCCVERSION=4.2.1
    
    # Select the desired iPhone SDK
    export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
    export SDKROOT=$DEVROOT/SDKs/iPhoneOS3.1.2.sdk
    
    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"
    
    # Set up relevant environment variables 
    export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/$GCCARCH/$GCCVERSION/include/ -I$SDKROOT/usr/include/"
    export CFLAGS="$CPPFLAGS -pipe -no-cpp-precomp -isysroot $SDKROOT"
    export CPP="$DEVROOT/usr/bin/cpp $CPPFLAGS"
    export CXXFLAGS="$CFLAGS"
    export LDFLAGS="-L$SDKROOT/usr/lib/ "
    
    CC=$DEVROOT/usr/bin/$GCCARCH-gcc-$GCCVERSION
    CXX=$DEVROOT/usr/bin/$GCCARCH-g++-$GCCVERSION
    HOST=arm-apple-darwin
    
    if [ ! -f $CC ]
    then
            echo "C Compiler not found! - $CC"
            exit
    fi
    
    if [ ! -f $CXX ]
    then
            echo "C++ Compiler not found! - $CXX"
            exit
    fi
    
    # TODO: add custom flags as necessary for package
    ./configure --prefix=$PREFIX --disable-dependency-tracking CXX=$CXX CC=$CC LD=$DEVROOT/usr/bin/ld --host=$HOST
    
    make -j4
    
    # copy the files to the arch folder
    
    mkdir -p $OUTPUTDIR
    mkdir -p $OUTPUTDIR/$ARCH
    
    cp `find . -name \*.a` $OUTPUTDIR/$ARCH/
    
    lipo -info $OUTPUTDIR/$ARCH/*.a
    
    echo $ARCH DONE
    
    echo "See $OUTPUTDIR"
    

    【讨论】:

      【解决方案4】:

      这个问题已经在一年前提出了,并且已经解决了。请参阅Help on installing a library like libical into Xcode,其中包含交叉编译和进一步链接的提示。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-11
        • 1970-01-01
        • 2013-07-10
        • 2018-05-02
        • 1970-01-01
        • 2011-01-26
        相关资源
        最近更新 更多