您的位置:首页 > 移动开发 > IOS开发

ios 模拟器和真机 使用同一静态库

2014-04-03 10:42 323 查看
今天搞服务器的同事合作写一个demo,服务器那边将之前在linux下已经写好的静态库传过来,我将这些静态库添加到xcode工程中,在模拟器上运行提示 architecture i386类错误,后来看了一些资料总结问题就是交叉编译的问题。

我把遇到的情况写一个测试例子代码如下

例如server端写一个静态库:

[cpp] view
plaincopyprint?

test.h

#include <stdio.h>



void test();

[cpp] view
plaincopyprint?

test.c

#include "test.h"



void test()

{

printf("this is server test static library");

}

编译:gcc -c test.c(默认生成与系统一样架构的静态库,如果系统为i386就是i386架构,如果系统为x86_64该静态库就是x86_64架构的)

ar rcs libtest.i836.a test.o

gcc -c test.c -arch armv7(这个是指定编译成arm架构的,默认会调用arm-apple-darwin11-llvm-gcc-4.2编译器,有时候版本号有可能会不同)

ar rcs libtest.armv7.a test.o

最后合并不同架构的静态库

[cpp] view
plaincopyprint?

lipo -create libtest.i386.a libtest.armv7.a -output libtest.a

这样在xcode中引入libtest.a和test.h在真机编译和在模拟器编译都OK了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: