通过Makefile在iPhone下创建Dylib实例

移动开发 iOS
本文介绍的是通过Makefile在iPhone下创建Dylib实例,主要是来解决如何通过Makefile在iPhone下创建Dylib,来看内容。

通过MakefileiPhone下创建Dylib实例是本文要介绍的内容,首先我要声明下经过测试,第三方的dylib是无法在未越狱的iphone上c成功运行的。写这篇文章也只是为了完善之前的那篇文章。

1、创建dylibtest.c 和.h

这里随便写了个test函数。

dylibtest.h

void test();
 
dylibtest.c

  1. #include "dylibtest.h"  
  2. #include "stdio.h"  
  3. void test() {  
  4.     printf("this is a test\n");  
  5. }  
  6.  
  7. makefile   
  8.  
  9. CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc  
  10. CFLAGS= -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk  
  11. CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp  
  12. target:  
  13.  $(CC) $(CFLAGS) -dynamiclib -o sotest-iphone.dylib dylibtest.c 

这里用的是sdk4.2 arch为armv6,另外需要提醒的事,如果你编译的是.m文件使用到framework的话编译时可以这样写

  1. -framework Foundation 

下面是测试代码 testdylib

关键代码如下:

  1. NSString *path = [[NSBundle mainBundle] pathForResource:@"sotest-iphone" ofType:@"dylib"];  
  2. void* handle = dlopen([path cStringUsingEncoding:NSUTF8StringEncoding], RTLD_LAZY);  
  3. if (!handle) {  
  4.     printf("%s\n", dlerror());  
  5.     return;  
  6. }  
  7. void (*test)();  
  8. test = (void (*)())dlsym(handle, "test");  
  9. const char *dlsym_error = dlerror();  
  10. if (dlsym_error) {  
  11.     printf("%s\n", dlsym_error);  
  12.     dlclose(handle);  
  13.     return;  
  14. }  
  15. // use it to do the calculation  
  16. test();      
  17. // close the library  
  18. dlclose(handle); 

你可以去测试下了,不过相信结果应该不会很让你满意。

小结:通过MakefileiPhone下创建Dylib实例的内容介绍完了,希望本文对你有所帮助!

责任编辑:zhaolei 来源: 互联网
相关推荐

2011-07-18 15:42:20

Xcode iPhone dylib

2013-08-13 09:54:39

iPhone 4iPhone 5iOS 7

2010-11-19 10:01:08

Oracle创建实例

2011-08-10 11:01:54

iPhoneNSThreadRun Loop

2011-07-25 18:02:51

iPhone LibFetion 移植

2023-09-08 14:48:41

动态共享包HSP

2023-09-07 15:45:30

静态库鸿蒙

2011-08-10 10:18:22

iPhone多线程线程

2010-11-03 13:55:39

创建DB2实例

2011-08-08 16:56:44

iPhone 字符处理 视图

2011-12-25 21:00:30

iPhone

2009-06-17 09:01:20

JBoss访问EJB

2009-11-30 17:40:05

juniper路由

2015-08-14 10:32:10

CentOSOpenStack搭建本地源

2011-07-06 16:15:46

iPhone 图片

2011-08-02 14:23:09

iPhone UIScrollVi 图片

2011-07-06 18:31:21

Xcode 4 iPhone 模拟器

2011-07-18 13:37:53

2011-07-18 15:32:14

iPhone 录音 播放

2011-07-22 17:24:46

iPhone 视图
点赞
收藏

51CTO技术栈公众号