从静态库中提取函数名称

发布于 2024-08-29 22:54:05 字数 119 浏览 5 评论 0原文

我有一个静态库 static_library.a

如何列出其中实现的函数和方法。
或者至少:如何查看特定函数 FUNCTION_NAME 是否已实现?

I have a static library static_library.a

How to list functions and methods implemented in there.
Or at least: how to look if a particular function FUNCTION_NAME is implemented?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绮烟 2024-09-05 22:54:05

Write

nm static_library.a

这为您提供了库中符号的完整列表。

Write

nm static_library.a

This gives you complete list of symbols in the library.

一身骄傲 2024-09-05 22:54:05

如前所述,使用 nm

如果这是一个从 C++ 构建的库,您应该使用 nm --demangle 选项来获取原始符号名称而不是它们的“损坏”版本。

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.

罗罗贝儿 2024-09-05 22:54:05

目标文件中的符号

$ nm <object file or executable name>

nm 列出了 看一个示例:

//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.

输出由三个部分、地址、类型(内部或外部符号)名称组成,看起来像

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

您可以找到示例 这里

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文