5

I can't figure out how to create a cocoa touch static library in Xcode 4.

I've created static library in Xcode 3 and it worked fine. I used this tutorial. Thanks for the help.

First step I create cocoa touch static library

enter image description here

Next we can see our static library in product directory. But now this uncompiled library.

enter image description here

Next step I add some objective-c class. This class is will perform various actions, for example show NSLog messages.

enter image description here

Then I made sure there is this class exist in compile source

enter image description here

After that I build my target

enter image description here

Now I use this static library in other projects, but when I use it I get a error when linking files with my static library.

Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277

3 Answers3

1

Open Xcode > Create New Project > iOS > Framework & Library > Cocoa Touch Static Library

edc1591
  • 10,146
  • 6
  • 40
  • 63
  • I did as you wrote. Then I created a few classes and do build my library. After that I drag my build library and header classes into my other project. When I import header and call some method in my static library and after run i get error: ld: warning: ignoring file /Users/dev01/Desktop/libLiba.a, missing required architecture i386 in file Undefined symbols for architecture i386: "_OBJC_CLASS_$_MyClass", referenced from: objc-class-ref in new2AppDelegate.o ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status – Matrosov Oleksandr Sep 16 '11 at 10:28
  • What is /Users/dev01/Desktop/libLiba.a? – edc1591 Sep 16 '11 at 21:06
  • I changed my post. Now I have described my steps to create a static library. – Matrosov Oleksandr Sep 19 '11 at 09:31
  • 2
    Do you get that error when you compile the project for the simulator or for an actual device? The fact that it says architecture i386 is missing sounds like your compiling your new project for the simulator, but the static library is compiled for the device. – edc1591 Sep 19 '11 at 14:16
  • Yes, I realized the error, it really is that as you write. i build my static lib for iOS Device and Run it on simulator. You know how to make a library for simulator and device? – Matrosov Oleksandr Sep 27 '11 at 08:17
  • I don't think you can. It's either one or the other. You can however, make your static library a sub-project of your app in Xcode and compile them both at once. – edc1591 Sep 27 '11 at 12:35
1

I struggled with this myself and, on another SO thread, found this:

iOS-Universal-Framework

Community
  • 1
  • 1
Doug Hays
  • 1,507
  • 11
  • 13
0

To create an static library you can try to figure out with example example here: http://www.raywenderlich.com/41377/creating-a-static-library-in-ios-tutorial

Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277