views:

1181

answers:

2

Hi All,

I have created a static library following this link.

But I am facing Problems in using the library. For reference on how to use static libraries in an iPhone project I followed this link .

But I am stil struggling with the "How to implement static libraries in any other iPhone project?" question.

Thank you all.

+3  A: 

You can use cross-project referencing as in the posts but this has several downturns.

I use this setup that works on Xcode in general (not only for the iPhone) and adds compile-time static library version control.

I put my static libraries in ~/Library/MyLibraries/, the .a archive along with their public headers. This way you can have different versions of them:

~/Library/MyLibraries/
                     /MyLib-1.0.0/Headers/header1.h
                                         /header2.h
                                 /libmylib.a
                                 /libmylib_debug.a
                     /MyOtherLib-2.1.0/Headers/...
                                      /libmyotherlib.a

Then in Xcode settings add the user variables:

LIBRARIES_DIR      $(USER_LIBRARY_DIR)/MyLibraries
MYLIBRARY_LIBROOT  $(LIBRARIES_DIR)/MyLib-1.0.0

and modify the settings

HEADER_SEARCH_PATHS $(MYLIBRARY_LIBROOT)/Headers
OTHER_LDFLAGS       $(MYLIBRARY_LIBROOT)/libmylib.a

Now change MYLIBRARY_LIBROOT to choose your library version. More on this blog post by myself ;)

If you want to keep it simple then just compile the library and setup HEADER_SEARCH_PATHS and OTHER_LDFLAGS.

IlDan
The drawback (which might be a benefit, depending on your needs) of this approach is that the static library will not automatically re-compile when you compile the projects that use them.
Felixyz
Certainly. But you want to develop and debug and test your library separately, that's the point of having a real library. You'll go out of sync soon anyway... ;)
IlDan
+3  A: 

I've created a complete tutorial on how to create and use static libraries, this tutorial covers the the method that is also advised by apple, maybe people will find it usefull:

http://www.sodeso.nl/?p=822

Advantages of this methods is that it automatically recompiles the library according to your project settings (so no trouble with device / simulator builds)

ronaldmathies