1

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?

jscs
  • 63,694
  • 13
  • 151
  • 195
user913059
  • 579
  • 4
  • 19
  • this is for iPhone, you can't just get .a files and use them. You need to cross-compile the code for the iPhone which will probably require you setting the CFLAGS environment variable to make it compile iPhone compatible code. You'll also need a separate version for use in the iPhone simulator. Or, you could just put the source files directly into your project. – Maz Aug 25 '11 at 22:29
  • thanks for the reply, I haven't used CFLAGS before and couldn't find them in the readme file, any help on what I need to do? – user913059 Aug 25 '11 at 22:36
  • OK, I think I've managed to compile it but now I get the following error when I build: Undefined symbols for architecture i386: "_bswap_32", referenced from: _decode in libical-static.a(icaltz-util.o) ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status – user913059 Aug 26 '11 at 00:35
  • You're compiling for i386, that is x86 architecture, the actual iPhone is ARM architecture. You'll need to compile two versions, one for the iPhone simulator, one for the actual device. It will be easiest to integrate the source files into your project or make it into an iPhone framework. – Maz Aug 26 '11 at 02:43
  • aah ok, so I have quite a few different libraries, the i386 one (is this even needed if I'm running lion, isn't it for old processors?) then I have the x86_64 one (I'm assuming this is what I need for the simulator, do I need to add anything into the target valid architectures like x86_64?) and the last one is the one compiled using ./configure -build=arm-apple-darwin9.0.0d1 so I'm assuming that's the arm one that's used on the device – user913059 Aug 26 '11 at 09:48
  • So I'm guessing I need to add the x86_64 and arm .a files to frameworks, is this ok even though they have the same filenames? – user913059 Aug 26 '11 at 09:49
  • @user913059 Can you share the full command you ran to configure? I can't get past the _bswap_32 error during make. – Jason Medeiros Dec 05 '11 at 20:03
  • possible duplicate of [Help on installing a library like libical into Xcode](http://stackoverflow.com/questions/3115810/help-on-installing-a-library-like-libical-into-xcode) – jscs Dec 05 '11 at 21:06
  • I've found a useful answer that explicitly address the needs of libical. See my answer below. – Jason Medeiros Dec 06 '11 at 19:17

4 Answers4

2

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"
Brennan
  • 11,546
  • 16
  • 64
  • 86
  • Do you know the reason for the failure if you change the arch to i386: /usr/bin/lipo: specifed architecture type (i386) for file (../libical-build/i386/libical.a) does not match its cputype (12) and cpusubtype (11) (should be cputype (7) and cpusubtype (3)) ? – Alexander Sep 27 '12 at 14:53
  • got it working, should have chosen iPhoneSimulator${SDKVER}.sdk in the shell script... – Alexander Sep 28 '12 at 09:26
  • @Brennan, did you update the scripts to compile libical v1.0 with LLVM 5 for iOS 7, including the arm64 architecture? Any chance to access the updated scripts ? Thank you in advance. – Massimo Cafaro Feb 10 '14 at 17:00
  • @MassimoCafaro I've been trying to build for iOS7 with little luck. It seems the latest libical has transitioned to cmake for builds, so this script is no longer valid. Unfortunately, I have not yet been able to cross-compile using cmake :( – AJD Mar 13 '14 at 16:29
  • This [answer](http://stackoverflow.com/questions/22986302/compiling-libical-for-arm64-and-x86-64-for-ios) modifies the script for iOS7. – ahalls May 02 '14 at 18:23
1

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

Ray Garner
  • 932
  • 1
  • 10
  • 18
1

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"
Jason Medeiros
  • 5,358
  • 3
  • 25
  • 18
0

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.

Community
  • 1
  • 1
ott--
  • 5,642
  • 4
  • 24
  • 27