Xcode 4.3: creating a static library

I looked around a bit, but most of the answers I found were or were incomplete, and I was a little embarrassed. I was provided with the C library, which I need to compile into a static library using Xcode 4.3, and then use the iOS application in a separate project, but I'm not sure how to do it. I'm not sure if the directory structure matters or not, but here anyway:

Library -> Section1 -> src -> .c files -> sec1 -> .h files -> sec1.h -> Section2 -> src -> .c files -> sec2 -> .h files -> sec2.h 

I tried to work from this: http://blog.stormyprods.com/2008/11/using-static-libraries-with-iphone-sdk.html , which was related in a question like this, although it has been from 2008 on quite outdated and I could not get it to work. There is also this question: Including an external C library with Xcode , but it is not included in the details of the actual generation of the library before including it in a separate project.

If someone can give a clear and relevant answer, I and many others, I am very grateful for this, I am sure. Let me know if you need more information!

+5
source share
2 answers

To create a static library:

  • Create a static library project in Xcode
  • Add all .c and .h file to the project
  • Compile

The easiest way to use this library is to add this static library project to the application project. This allows you not to worry about creating thick libraries (that is, libraries with code for the simulator and device).

To add a static library project to an application project:

  • Choose File> Add Files To ...
  • Add .xcodeproj for your static library
  • Click on your .xcodeproj application in the Project Navigator to display the build options.
  • Click on the target application and select the Build Phases tab.
  • Expand the link "Link with binaries"
  • Click the "+" button
  • Expand the "Workspace" section (you will see your library, the .a file) there
  • Click on your library and you should be fine.

Sorry for the excruciating level of detail above, but for some reason people always seem to forget to do steps 4-8, and then wonder why they get link errors!

Xcode cannot find headers for your library. You can add public headers to your project, like any other header file, or set "header search paths" in the build settings.

+7
source

Try the Universal Framework project, as shown on github: https://github.com/kstenerud/iOS-Universal-Framework/ . I have used this extensively and it works beautifully. You simply create a new Xcode project for this library, put all the source and header files, and it will create a static environment. This can be used in other projects, and you also do not need to worry about heading search paths.

0
source

Source: https://habr.com/ru/post/1011921/


All Articles