xcode 为 iPhone 应用程序编译自定义 SQLite
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/823706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Compiling custom SQLite for an iPhone app
提问by John Biesnecker
I'm trying to compile the SQLite amalgamationsource into my iPhone app (to give me access to the full-text searching functionality that isn't available in the iPhone-compiled version of the binary.
我正在尝试将SQLite 合并源编译到我的 iPhone 应用程序中(以使我能够访问在 iPhone 编译版本的二进制文件中不可用的全文搜索功能。
When I add sqlite3.c and sqlite3.h to a normal Carbon C app template, it compiles just fine (with a single warning about an unused variable), but when I try compiling it in my iPhone project I get a number of errors relating to missing function declarations. I'm able to solve these problems by explicitly including ctype.h, but it's a little strange.
当我将 sqlite3.c 和 sqlite3.h 添加到普通的 Carbon C 应用程序模板时,它编译得很好(有一个关于未使用变量的警告),但是当我尝试在我的 iPhone 项目中编译它时,我得到了一些相关的错误缺少函数声明。我可以通过显式包含 ctype.h 来解决这些问题,但这有点奇怪。
However, even after it builds it fails on linking with the following error:
但是,即使在它构建之后,它也无法链接并出现以下错误:
"_sqlite3_version", referenced from:
_sqlite3_version$non_lazy_ptr in sqlite3.0
symbol(s) not found
collect2: ld returned 1 exit status
I assume that it's something in the iPhone app's build settings, but I can't figure it out. Any ideas?
我认为这是 iPhone 应用程序的构建设置中的某些内容,但我无法弄清楚。有任何想法吗?
采纳答案by catlan
Try it with this steps:
请按照以下步骤尝试:
- xcode menu -> project -> new target -> static library -> target name: SQLite
- drop SQLite amalgamation source into the project, now you can select the target, choose SQLite
- xcode menu -> project -> edit active target -> tab General -> Direct Dependencies -> add SQLite
- tab General -> Linked Libraries -> add your SQLite
- xcode 菜单 -> 项目 -> 新建目标 -> 静态库 -> 目标名称:SQLite
- 将 SQLite 合并源放到项目中,现在可以选择目标,选择 SQLite
- xcode 菜单 -> 项目 -> 编辑活动目标 -> 选项卡 General -> Direct Dependencies -> 添加 SQLite
- 选项卡 General -> Linked Libraries -> 添加你的 SQLite
回答by arooaroo
I've managed to do this using the amalgamation and dumped it straight into my project without having to do the linking catlan suggested (I'm not saying it's a bad idea, merely it's possible to do in the main project).
我已经使用合并成功地做到了这一点,并将其直接转储到我的项目中,而无需执行 catlan 建议的链接(我并不是说这是一个坏主意,只是可以在主项目中进行)。
I didn't need to edit anything (except for adding the necessary FTS define for the text searching) and compiled error free. Check your build settings and ensure '-sqlite3' isn't in your Other Linking Flags.
我不需要编辑任何东西(除了为文本搜索添加必要的 FTS 定义)并且编译没有错误。检查您的构建设置并确保“-sqlite3”不在您的其他链接标志中。
回答by Alex Reynolds
That type of error usually means a missing framework.
这种类型的错误通常意味着缺少框架。
- Right- or control-click on your Project's Frameworksfolder.
- Select Add > Existing Framework...
- Go to: Macintosh HD > Developer > Platforms > iPhoneOS.platform > Developer > SDKs > iPhoneOS2.2sdk > usr > liband select libsqlite3.dylib
- Rebuild your project
- 右键或按住 Control 单击项目的Frameworks文件夹。
- 选择添加 > 现有框架...
- 转到:Macintosh HD > Developer > Platforms > iPhoneOS.platform > Developer > SDKs > iPhoneOS2.2sdk > usr > lib并选择libsqlite3.dylib
- 重建你的项目
That should take care of it, I think. You may need to add a similar library for running on the iPhone Simulator.
我想,那应该照顾它。您可能需要添加一个类似的库以在 iPhone 模拟器上运行。