Implementing Static Libraries In iPhone

2019-02-05 15:24发布

问题:

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.

回答1:

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 me.

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