手动编写dylib动态文件库 / mac下面的写交叉编译的makefile
(2015-08-08 20:22:33)
标签:
股票 |
手动编写dylib动态文件库 / mac下面的写交叉编译的makefile
OA上有篇文章讲的是用xcode怎么生成dylib动态文件库,这篇主要讲手动怎么写,主要给在mac下写交叉编译的makefile做个参考
1. 编写源文件
准备了一个hook用的category文件UIViewControllerswizzlin
//UIViewControllerswizzling.m
@implementation
UIViewController (swizzling)
-(void)newViewDidLoad
{
NSLog(@"[ ViewDidLoad:%@
]", [self class]);
[self newViewDidLoad];
}
@end
static
void
__attribute__((constructor))
initialize(void)
{
Class class
= objc_getClass("UIViewController");
Method ori_Method = class_getInstanceMethod(class,
@selector(viewDidLoad));
Method my_Method = class_getInstanceMethod(class,
@selector(newViewDidLoad));
method_exchangeImplementations(ori_Method, my_Method);
}
2. 写Makefile
和unix下面的makefile有点不一样,针对ios使用的动态库,还有一些配置
SDK=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk
Frameworks=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk/System/Library/Frameworks/
INCLUDES=-I.
all : UIViewControllerswizzling.o
UIViewControllerswizzling.o : UIViewControllerswizzling.m
clang -c $(INCLUDES) \
-F$(Frameworks) \
-target armv7-apple-darwini \
-mios-version-min=7.1 \
-fobjc-abi-version=2 \
-isysroot $(SDK) \
UIViewControllerswizzling.m -o UIViewControllerswizzling.o \
3. ld
同样需要一些设置
ld -dylib -lsystem -lobjc -arch armv7 -syslibroot $SDK -framework Foundation -framework
UIKit -framework CoreGraphics -o libwq.dylib
UIViewControllerswizzling.o 前一篇:....

加载中…