views:

116

answers:

1

Hi,

I think that I've looked everywhere for an answer to my problem but without any luck.

I'm trying to create a simple static lib to run on the iPhone device but I keep ending up with XCode saying that "file is not of required architecture" and I've tried every build flag that I found without any luck.

I've got it to work on the emulator building it like this:

$gcc-4.2 -c StaticHelloWorld.c -o StaticHelloWorld.o
$ar rcs libstatichelloworld.a StaticHelloWorld.o

But how do I build it for device??

Regards, drisse

+2  A: 

Within Xcode, there is a New Project template called Cocoa Touch Static Library. This template provides most of the setup you need for creating a static library. You then just need to include your various source files, as well as your shared header file.

For an example of iPhone static libraries, see the Three20 and Core Plot projects. Both employ static libraries for the iPhone. We have some instructions on how to include the library within an application in the main Core Plot wiki.

Brad Larson
I had to cross compile the lib for apple-darwin in order to get this to work: $ /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-gcc-4.2.1 -c StaticHelloWorld.c -o StaticHelloWorldArm.o$ ar rcs libstatichelloworld.a StaticHelloWorldArm.o
drisse