Compiling libical

半腔热情 提交于 2019-11-29 04:15:52

问题


I would like to compile libical and add it to my Xcode project.

I have read the README file and run the following commands in Terminal.app:

./configure

and

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

Am I supposed to get compiled .a files somewhere that I can drag and drop into my project?


回答1:


I am the person who originally created those build scripts located here...

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

I have now updated the scripts to work with the latest iOS 6/Xcode 4.5 toolset. It is quite different and I have set it to use Clang. I did what I could to make this script adapt to new SDK releases.

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

The scripts should be placed in the root of the libical folder and run from there. The main script runs the other 2 scripts to build the armv7 and armv7s binaries and then uses xcrun to run lipo for iphoneos to combine these binaries into a fat binary which can be used for an iOS project.

There are some refactorings which could easily be done but I have already spent a ton of time on it already. I hope this helps you make use of the library.

#!/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"



回答2:


What you do is compile your libraries for both simulator and phone.

1.Make 2 new targets one for iphone one for simulator

2.compile

3.Take them and combine them with lipo.

This link will give you all the specific details. How to make universal static libraries




回答3:


Other answers to this question aren't helpful for specifically libical, because its configure script is finicky. You need to have a ton of environment variables right. These scripts have figured all them out for libical.

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

Download the above scripts, and tweak the build_(platform).sh to find the right compilers and SDK folders. This will change depending on what you are targeting and how recent your Xcode developer tools are. Finding the right values should be pretty easy, just look in the same locations for what they are called on your system.

The output will be a fat ".a" files with binaries for the simulator and device.

In the case these files disappear, I've collected the truly important one (build_arm.sh, the cross-compile) below:

#!/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:


This question came up already a year ago, and it was solved. See Help on installing a library like libical into Xcode with hints for cross-compile and further link.



来源:https://stackoverflow.com/questions/7197955/compiling-libical

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!