1

I'm a new in framework development, here is my case. I build a private static library to provide it to the vendors to link it.

Currently, I build my library with arch armv7 and arm64 only, this should be work for vendors to debug it in iOS device and archive their apps, but not for debugging in iOS Simulator. The simulator needs the x86_64 ( and even i386 in iPhone 5 Simulator). It isn't friendly to disable the ability to debug it in a simulator. I'm considering to provide a fat architecture of static library for them.

Here is the action

lipo -create libSignatureLibary_armv6.a libSignatureLibary_armv7.a libSignatureLibary_i368.a -output libSignatureLibary.a

After the merge operation, the output library has a double size than the single one.

The question is, will the compiler/Xcode strip the i386 and x86_64 arch symbols from final app product binary? If not, the fat arch library will increase the product app's size directly, right? Should I build two versions of the library for vendors, one for debugging, another for archiving? What's the right solution for this case?

I don't know what keywords I should research, I didn't have an existing product app linking it to verify this, either. (Maybe I should build a new later.)

halfer
  • 19,824
  • 17
  • 99
  • 186
Itachi
  • 5,777
  • 2
  • 37
  • 69

1 Answers1

3

Don't worry, the linker only uses the .o (relocatable object file, it is the output file of assembler, when you build a static library, a .m file will be translated to a .o file. The static library is a collection of relocatable object files) files for target arch in the static library, so it will strip the x86_64 and i386 .o files when building product binary.

Also the linker won't link the .o file which is not referenced directly or indirectly by compiled files into executable file.

KudoCC
  • 6,912
  • 1
  • 24
  • 53
  • The relocatable object file is generated for every source file (.m), do that mean it will strip the unused class source file if I didn't use any symbols from that source file? – Itachi Dec 30 '16 at 04:28
  • It will strip the unused relocatable object file which is in the static library. When you're generating executable file, all the source files which are contained in `Build Phases->Compiled Sources` will be linked into the executable file. – KudoCC Dec 30 '16 at 04:39
  • Imagine that I build a Foo class in Foo.h/m, I create a macro like `#define FooMarker 1` in header file Foo.h, however, I never use any other symbols in Foo.h/m. The compiler will compile the Foo.m and other source files, for this case, the Foo class related symbols will be striped in final product binary file, too. Right? – Itachi Dec 30 '16 at 06:41
  • @Itachi You can check it with this command: `nm -g executable_file_name | grep 'class_name'` – KudoCC Dec 30 '16 at 08:08
  • Thanks for your explanation, which type of document should I read? Any suggestion? – Itachi Dec 31 '16 at 04:46
  • @Itachi I recommend Linking chapter of the book: Computer system a programmer's perspective – KudoCC Dec 31 '16 at 06:50
  • Thank you!! Check it out later. :) – Itachi Dec 31 '16 at 07:09