Export `OBJC_CLASS` from one static lib as part of another

I want to create a static library (in fact, a framework, but I know how to do this part), which links the code, among other things, to another static library. However, export OBJC_CLASSfrom the source library ends with the undefined character.

For example, in Xcode 5.1.1 (using the default settings / options at each step, unless otherwise specified):

  • Create a new iOS Framework project and Cocoa Touch Static Library named LibA.
    • Assembly (for a simulator or a real device does not matter).
  • Create another new iOS Framework project and Cocoa Touch Static Library called LibB.
    • Drag libLibA.afrom LibA products to the Frameworks folder in the LibB project tree.
    • Drag LibAfrom the directory includenext to the static lib to the top level of the LibB project tree.
    • Change LibB.has shown below.
    • Assembly (same goal as before).
  • Create a new iOS App project (of any type) called AppC.
    • Drag libLibB.afrom LibB products to the Frameworks folder in the AppC project tree.
    • Drag LibBfrom the catalog includeto the upper level.
    • Drag LibAfrom the first project includeto the top level.
    • Make sure that it LibAappears in the Link Binary With Libraries phase.
    • In any method of any class, the created master (for example, -[MasterViewController awakeFromNib]) adds (void)[[LibB alloc] init].
    • At the top of the file .myou just edited, add #import "LibB.h".
    • Build.

LibB.h :

#import <Foundation/Foundation.h>
#import "LibA.h"
@interface LibB: LibA
@end

:

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_LibA", referenced from:
      _OBJC_CLASS_$_LibB in libLibB.a(LibB.o)
  "_OBJC_METACLASS_$_LibA", referenced from:
      _OBJC_METACLASS_$_LibB in libLibB.a(LibB.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

, :

$ nm -g libLibB.a
         U _OBJC_CLASS_$_LibA
0000031c S _OBJC_CLASS_$_LibB
         U _OBJC_METACLASS_$_LibA
00000308 S _OBJC_METACLASS_$_LibB
         U _OBJC_METACLASS_$_NSObject
         U __objc_empty_cache

_OBJC_CLASS_$_LibA _OBJC_METACLASS_$_LibA undefined.

, C- , globals .. LibA. Foundation ( , ). , , .

:

  • Dead Code Stripping ( ).
  • -ObjC ( ). ( libs, , , , , .)
  • " " ( LibB). ( .)
  • Pass ${PROJECT_DIR}/libLibA.a " " ( LibB) libLibA ( , -lLibA , libLibA.a).

, , , , :

  • libtool, Xcode. ( Makefile Xcode, .)
  • " ", ${PROJECT_DIR}/libLibA.a "Prelink libraries". , , libLibB.a, , , - . .dylibs Framework OS X, ... libs.

, ( , ):

  • , , LibB, LibA . , , LibA, .
  • LibB , , lib .
  • ar libLibA.a LibB.o, ranlib 1999 ( , , ).

( , , LibA 80 3 , LibA fat arm7/armv7s ( , ar ...), , .

+3
1

, , , - ( , ld -r , libtool), , . , , , , - .

, ( LibB):

  • libLibA.a .
  • , .
  • " " "".
  • " " "" .
  • " " "" .
  • " Prelink" ${PROJECT_DIR}/libLibA.a
  • " " "" .

( - , ...)

, , -, , .m( .pch) , .

, , AppC, .

AppC " "; . , , ld -r -exported_symbols_list , " private_extern. . m 100% , .

+3

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


All Articles