问题描述:
在己经测试好的工程中,加入了一个新的静态库target,该target编译完全正常没有报任何错。然后在另一个工程中使用生成的.a文件,编译我链接都没有任务错误,但是在调用静态库中定义的某些函数时,出现对象不能接受该消息的错程,导致程序崩掉。
用nm命令查看发现,生成的.a文件中的确没有这个函数:
nm /Users/yndfcd/Library/Developer/Xcode/DerivedData/Kline-enfzvyhrpqalelaiqkncnjkpgcau/Build/Products/Debug-iphonesimulator/libKlineView.a
/Users/yndfcd/Library/Developer/Xcode/DerivedData/Kline-enfzvyhrpqalelaiqkncnjkpgcau/Build/Products/Debug-iphonesimulator/libKlineView.a(Foo.o):
0000000000000060 t -[Foo creatKlineView:]
0000000000000000 t -[Foo fooFunc1]
0000000000000030 t -[Foo fooFunc2]
0000000000009a80 s EH_frame0
0000000000008a2b s L_.str
0000000000008a36 s L_.str1
0000000000008ae0 s L_OBJC_CLASS_NAME_
0000000000008a98 s L_OBJC_METH_VAR_NAME_
0000000000008a9e s L_OBJC_METH_VAR_NAME_3
0000000000008aad s L_OBJC_METH_VAR_NAME_5
0000000000008ab6 s L_OBJC_METH_VAR_NAME_6
0000000000008abf s L_OBJC_METH_VAR_NAME_7
0000000000008c18 s L_OBJC_METH_VAR_TYPE_
0000000000008c20 s L_OBJC_METH_VAR_TYPE_8
U _NSLog
0000000000008bf0 S _OBJC_CLASS_$_Foo
U _OBJC_CLASS_$_NSObject
U _OBJC_CLASS_$_UIView
0000000000008bc8 S _OBJC_METACLASS_$_Foo
U _OBJC_METACLASS_$_NSObject
U ___CFConstantStringClassReference
U __objc_empty_cache
U _objc_autoreleaseReturnValue
U _objc_msgSend
0000000000008b30 s l_OBJC_$_INSTANCE_METHODS_Foo
0000000000008b80 s l_OBJC_CLASS_RO_$_Foo
0000000000008ae8 s l_OBJC_METACLASS_RO_$_Foo
/Users/yndfcd/Library/Developer/Xcode/DerivedData/Kline-enfzvyhrpqalelaiqkncnjkpgcau/Build/Products/Debug-iphonesimulator/libKlineView.a(KlineView.o):
00000000000002b4 s L_OBJC_CLASS_NAME_
0000000000000378 S _OBJC_CLASS_$_KlineView
U _OBJC_CLASS_$_NSObject
0000000000000350 S _OBJC_METACLASS_$_KlineView
U _OBJC_METACLASS_$_NSObject
U __objc_empty_cache
0000000000000308 s l_OBJC_CLASS_RO_$_KlineView
00000000000002c0 s l_OBJC_METACLASS_RO_$_KlineView
另附上foo.h和klineview.h的定义:
//
// Foo.h
// Kline
//
// Created by yndfcd on 15/4/9.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import “KlineView.h”
@interface Foo : NSObject
-(void)fooFunc1;
-(void)fooFunc2;
-(UIView*)creatKlineView:(CGRect)frame;
@end
//
// KlineView.h
// Kline
//
// Created by yndfcd on 15/3/27.
// Copyright (c) 2015年 BlueMobi. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface KlineView : UIView
@property (nonatomic,strong) NSArray* rawData;
@property (nonatomic,assign) int startPos;
@property (nonatomic,assign) CGFloat segmentWidth;
@property (nonatomic,assign) CGFloat macdHeight;
@property (nonatomic,assign) CGFloat maHeight;
@property (nonatomic,assign) CGFloat diagramWidth;
@property (nonatomic,assign) CGFloat leading;
@property (nonatomic,assign) CGFloat top;
-(void)fetchData;
-(id) initWithFrame:(CGRect)frame;
@end
在foo.o中定义的函数调用均正常,包括返回一个UIView对象的那个方法,尝试在Foo中加一个方法返回一个KlineView类的对象仍然会崩掉,原因是KlineView不能接收initWithFrame消息。从上面nm打印的结果来看,KlineView的基类似乎是NSObject.