Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pre-link static libraries for ios project

I have a big iOS project that consists from several (about 20-30) static libraries that link together into final executable. Some of the components are platform-independent (pure C++) and some are iOS-specific (Obj-C/Obj-C++). C++ templates are used intensively, so each object file contains lots of symbols with vague linkage. The problem is that these symbols are merged only during linking of the final executable, but not when making static libraries. Each library contains tons of duplicated symbols (6-60 clones). So final linking of the app takes several minutes. This becomes extremely annoying when debugging and doing some small changes.

Is there a way to perform merging of the symbols with vague linkage for each library?

I known, that this is done automatically when using dynamic libraries. With some hacking (http://sumgroup.wikispaces.com/iPhone_Dynamic_Library) it is possible to build dynamic libraries for iOS. Is there a way to link dylib's statically (link them into a single executable file)?

Of course, being able to debug resulting app is a must.

like image 759
kjam Avatar asked Jan 10 '13 13:01

kjam


People also ask

Should I add a static library as a subproject?

If you’re using your own library, or if you have access to the source and project files, adding the library as a subproject provides a convenient way to import a static library in your app. You get closer build integration as a project dependency, with fewer things to worry about doing yourself.

How do I run a static library in Xcode?

You will notice the usual Xcode “Run” button just performs a build; you can’t actually run your library to see the results as there’s no app behind it! Rather than a .app or a .ipa file, a static library has the .a extension. You can find the generated static library in the Products folder in the project navigator.

What is the extension of a static library?

Rather than a .app or a .ipa file, a static library has the .a extension. You can find the generated static library in the Products folder in the project navigator.

Are iOS and macOS system libraries dynamic or static?

All iOS and macOS system libraries are dynamic. Hence our apps will benefit from the future improvements that Apple makes to standard library frameworks without creating and shipping new builds. When we link system libraries, such as UIKit or Foundation, we don’t want to copy their entirety into the app, because it would be too large.


1 Answers

You can pre-link your static library objects into a single one, also you can prelink other static libraries into one. It will actually link objects with the linker (almost like in dynamic library).

  1. In your single library (the main one) go to Build Settings and find Perform Single-Object Prelink in Linking sections. Switch that to Yes
  2. In Prelink libraries you can specify other libraries you want to include. There you need to put not just names, but full file name. If other libraries are also from your project, then you can use $(CONFIGURATION_BUILD_DIR) variable. So if you have library foo, then it will be $(CONFIGURATION_BUILD_DIR)/libfoo.a
  3. You can add additional flags in Single-Object Prelink Flags
  4. If you want to strip out local symbols, then make sure that you have Deployment Postprocessing set to Yes, as by default static libraries are not stripped out.
like image 55
Dmitry Avatar answered Sep 17 '22 23:09

Dmitry