Function names extraction from static library
I have a static library static_library.a
How to list funct开发者_如何学Cions and methods realized there. or at least how to look is there concrete function 'FUNCTION_NAME' realized?
Write
nm static_library.a
This gives you complete list of symbols in the library.
Use nm <library>
as mentioned.
If this is a library built from C++ you should use the nm --demangle
option to get back the original symbol names rather than their "mangled" versions.
The nm
lists the symbols from object files
$ nm <object file or executable name>
Let's take a look at an example:
//GFICClassA.h
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface GFICClassA : NSObject
//global constants
extern int const GFIC_GLOBAL_EXTERN_CONST_INT_1;
extern NSInteger const GFIC_GLOBAL_EXTERN_CONST_NSInteger_1;
extern NSString *const GFIC_GLOBAL_EXTERN_CONST_NSString_1;
//Public properties first
@property (nonatomic, strong) NSString *GFICGlobalPropertyNSString1;
//class methods
+ (NSString*)GFICclassMethod1:(NSString*)arg1 :(NSString*)arg2;
//instance methods
- (NSString*)GFICinstanceMethod1:(NSString*)arg1 :(NSString*)arg2;
- (void) GFICprintHelloWorld;
@end
NS_ASSUME_NONNULL_END
//GFICClassA.m
#import "GFICClassA.h"
// Declare global constants
int const GFIC_GLOBAL_EXTERN_CONST_INT_1 = 1;
NSInteger const GFIC_GLOBAL_EXTERN_CONST_NSInteger_1 = 1;
NSString *const GFIC_GLOBAL_EXTERN_CONST_NSString_1 = @"GFIC_GLOBAL_EXTERN_CONST_NSString_1_value";
// Declare local constants
static NSString *const GFIC_LOCAL_STATIC_CONS_1 = @"GFIC_LOCAL_STATIC_CONS_1_value";
@interface GFICClassA ()
@property (strong, nonatomic) NSString *GFICLocalPropertyNSString2;
@end
@implementation GFICClassA
//class methods
+ (NSString*)GFICclassMethod1:(NSString*)arg1 :(NSString*)arg2 {
printf("GFI classMethod1 called");
return @"GFI classMethod1_result";
}
//instance methods
- (NSString*)GFICinstanceMethod1:(NSString*)arg1 :(NSString*)arg2{
printf("GFI instanceMethod1 called");
self.GFICGlobalPropertyNSString1 = @"gfiGlobalPropertyNSString1_value";
self.GFICLocalPropertyNSString2 = @"gfiLocalPropertyNSString2_value";
return GFIC_GLOBAL_EXTERN_CONST_NSString_1;
}
- (void) GFICprintHelloWorld {
NSLog(@"Hello World! from ObjC");
}
@end
nm -U libObjCUtils.a
//-U Don't display undefined symbols.
The output consists of thee parts, address, type(internal or external symbol) name and looks like
libObjCUtils.a(GFICClassA.o):
0000000000000000 t +[GFICClassA GFICclassMethod1::]
0000000000000290 t -[GFICClassA .cxx_destruct]
00000000000001d0 t -[GFICClassA GFICGlobalPropertyNSString1]
0000000000000230 t -[GFICClassA GFICLocalPropertyNSString2]
00000000000000b0 t -[GFICClassA GFICinstanceMethod1::]
00000000000001a0 t -[GFICClassA GFICprintHelloWorld]
00000000000001f0 t -[GFICClassA setGFICGlobalPropertyNSString1:]
0000000000000250 t -[GFICClassA setGFICLocalPropertyNSString2:]
00000000000002e8 S _GFIC_GLOBAL_EXTERN_CONST_INT_1
00000000000002f0 S _GFIC_GLOBAL_EXTERN_CONST_NSInteger_1
0000000000000538 S _GFIC_GLOBAL_EXTERN_CONST_NSString_1
0000000000000540 s _GFIC_LOCAL_STATIC_CONS_1
00000000000008a8 S _OBJC_CLASS_$_GFICClassA
0000000000000658 S _OBJC_IVAR_$_GFICClassA._GFICGlobalPropertyNSString1
0000000000000660 S _OBJC_IVAR_$_GFICClassA._GFICLocalPropertyNSString2
0000000000000880 S _OBJC_METACLASS_$_GFICClassA
00000000000006b0 s l_OBJC_$_CLASS_METHODS_GFICClassA
0000000000000718 s l_OBJC_$_INSTANCE_METHODS_GFICClassA
00000000000007c8 s l_OBJC_$_INSTANCE_VARIABLES_GFICClassA
0000000000000810 s l_OBJC_$_PROP_LIST_GFICClassA
0000000000000838 s l_OBJC_CLASS_RO_$_GFICClassA
00000000000006d0 s l_OBJC_METACLASS_RO_$_GFICClassA
You can find samples here
精彩评论