5

I'm building a iOS static library for third parties to use. It's built using several other static libraries containing a large amount of C++, resulting in a huge deliverable library.

The API to the iOS library is quite simple, and I know that it doesn't exercise all of the included code. I'd like to remove the unwanted modules from the various libraries so I can get the final size down.

I have an example app which uses all the library APIs, and when it's linked most of the symbols in the library are discarded. Is there a way of getting a list of those symbols?

pineweasel
  • 123
  • 1
  • 4

2 Answers2

0

This answer seems to indicate that what you want to do isn't possible in GCC 3.x and 4.x:

Restricting symbols in a Linux static library

Community
  • 1
  • 1
prairiedogg
  • 6,323
  • 8
  • 44
  • 52
0

I’ve been told that the restriction upon using dynamic library is enforced by the code signing process so I think this might work:

  1. Link the executable of your example application against the static library
  2. Run nm -uj to list the undefined symbols in the executable. Since the library has been linked statically, the only undefined symbols should be the ones defined by the standard iOS libraries
  3. Create a dynamic version of the static library
  4. Link the executable of your example application against the dynamic library
  5. Run nm -uj against this executable. The undefined symbols are the union of the ones listed in step 2 with the library symbols that are actually referenced by the executable
  6. diff the lists from step 2 and step 5. This will give you the list of symbols in the library only
  7. Run nm -js __TEXT __text on the object files to get a list of the functions exported by each object file
  8. Add to the library only the object files that export a function listed in step 6.

This can be automated and probably needs to be improved to take into account symbols other than functions (e.g. global variables).