【发布时间】:2009-07-14 23:36:53
【问题描述】:
我有一个内置于 Macosx ibopencore-amrnb.a 中的库。我可以将它与我的 Iphone 应用程序一起用作图书馆吗?如果是怎么办?如果不是,我如何让图书馆与 Iphone 应用程序一起使用?
谢谢, 索瑞
【问题讨论】:
我有一个内置于 Macosx ibopencore-amrnb.a 中的库。我可以将它与我的 Iphone 应用程序一起用作图书馆吗?如果是怎么办?如果不是,我如何让图书馆与 Iphone 应用程序一起使用?
谢谢, 索瑞
【问题讨论】:
Mac osX 是 X86 平台,iphone 使用 ARM 处理器,因此至少需要重新编译。不过,架构非常不同,因此必须考虑诸如 endeaness(?) 和字长等因素。
【讨论】:
第 1 步)构建静态库。
我已经为 iPhone 静态构建了第三方库。经过一番反复试验,我发现这是一个很好的起点:
针对 iPhoneOS 的交叉编译:
./configure --prefix=/path/to/project/external/iphoneos/ --host="arm-apple-darwin9" --target=arm-apple-darwin9 --enable-static --disable-共享 CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-gcc-4.0.1 CFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0 .sdk" CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp 制作 进行安装
iPhoneSimulator 的交叉编译:
./configure --prefix=/path/to/project/external/iphonesimulator --enable-static=yes --enable-shared=no CC=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin /gcc-4.0 CFLAGS="-arch i686 -pipe -mdynamic-no-pic -std=c99 -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -mmacosx-version-min=10.5 -I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/include/ -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/ SDKs/iPhoneSimulator3.0.sdk" CPP=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar LDFLAGS="-arch i686 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk -Wl,-dead_strip -mmacosx-version-min=10.5" 制作 进行安装
但是,这实际上只是一个起点。它可能只适用于具有灵活 Makefile 的项目。如果上述方法不起作用,我必须:
您还可以为 iPhoneOS 版本打开优化标志(在您先让它工作之后)。
第 2 步)将库添加到项目的搜索路径中。
在您的项目信息设置中,设置以下构建选项:
标头搜索路径:“$(SRCROOT)/external/$(PLATFORM_NAME)/include”
库搜索路径:“$(SRCROOT)/external/$(PLATFORM_NAME)/lib”
其他链接器标志:[为您的静态库添加标志]
之后,您应该能够在项目中包含第三方库。
【讨论】: