为iPhone创建静态库 [英] Creating static library for iPhone

查看:99
本文介绍了为iPhone创建静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的iPhone应用程序中使用一个开源库。该库是用C语言编写的,并使用Makefile编译。我想使用一个静态库。

There's an open source library that I would like to use for my iPhone app. The library is written in C and compiles with Makefiles. I would like to use a static library.

如果我将.a文件添加到我的项目依赖项中,它可以很好地与模拟器一起使用,但是它不会链接时定位iPhone SDK(当然因为.a文件是为Intel平台编译的)。

If I add the .a file to my project dependencies, it works well with the simulator, but it doesn't link when targeting the iPhone SDK (certainly because the .a file is compiled for an Intel platform).

我应该使用哪些GCC编译器标志来编译iPhone SDK的静态库?我认为'-arch'选项会为我提供iPhone架构,但没有运气。

What GCC compiler flags should I use to compile a static library for the iPhone SDK? I thought that the '-arch' option would provide me with an iPhone architecture, but no luck.

任何帮助都将不胜感激。

Any help would be appreciated.

推荐答案

对于基于autoconf的库,我会投票给Christopher Stawarz的构建脚本:

For autoconf based library, I would vote for Christopher Stawarz's build script:

http://pseudogreen.org/blog/build_autoconfed_libs_for_iphone.html

使用此脚本,您可以使用单个命令自动执行整个过程,并轻松地为不同平台提供库二进制文件,例如iPhoneOS 2.0 / 2.1 / 2.2 / 2.2.1和iPhoneSimulator 2.0 / 2.1 / 2.2 / 2.2 .1。

With this script, you can automate the whole process with single command, and easily come up with library binaries for different platforms, such as iPhoneOS 2.0/2.1/2.2/2.2.1 and iPhoneSimulator 2.0/2.1/2.2/2.2.1.

但是,由于 Xcode 3.1的更改,$(SDKROOT)构建设置变成了一些短名称,如macosx10.5,iphoneos2.2.1或iphonesimulator2.2.1。因此,他在文章中提到的关于在Xcode中为库和标题设置搜索路径的方式将不起作用(在Xcode 3.1中)。您需要自己对路径进行硬编码。

However, due to the change of Xcode 3.1, the $(SDKROOT) build setting had became some short names like "macosx10.5", "iphoneos2.2.1" or "iphonesimulator2.2.1". So, the way he mentioned in the article about setting search path in Xcode for library and header will not work (in Xcode 3.1). You will need to hard code the path by yourself.

这篇关于为iPhone创建静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆