libsqlite in simulator and iOS compiling

2019-01-25 08:02发布

I'm having some issues when compiling my app to iOS. I'm using sqlite3 and imported as

#import <sqlite3.h>

Well, I only found a file named libsqlite3.0.dylib in my Mac and I copied it to my project. When I compile it for iOS Simulator, it works just fine. However, when I try to compile the app for iOS Device, it throws an error (Apple Match-O Linker Error) in every call I do in my implementation to sqlite's function (such as _sqlite3_open, etc.)

How can I compile it to iOS Device?

Thank you!

4条回答
地球回转人心会变
2楼-- · 2019-01-25 08:14

Did you try to import sqlite3 library like:

#import "sqlite3.h"

instead of:

#import <sqlite3.h>

查看更多
劫难
3楼-- · 2019-01-25 08:23

Instead of simply copying the library, do it like this:

  • in Xcode Navigator, click on your target (the upmost entry)

  • go to Build Phases, then Link Binary With Libraries

  • add the libsqlite3.dylib from it's location at /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOSxx.sdk/usr/lib/

查看更多
4楼-- · 2019-01-25 08:23

The best way that I have found to use SQLite in your IOS application is to build your own copy of the SQLit library and include it in your project. libsqlite3.0.dylib is a very old copy of SQLite.

You can easily download the SQLite Amalgamation source code and build it for IOS. this gives you the latest SQLite source code that has all the latest bug fixes and improvements.

If you can open Xcode and create a new static library project, then you are 75% of the way there.

Once you have the static library project, include the SQLite sources that you downloaded from the SQLite Amalgamation and set a few Preprocessor options and your off and running with the latest code.

For complete details and sample source code you can visit my blog conedogers

查看更多
Evening l夕情丶
5楼-- · 2019-01-25 08:34

Just in case someone faced that same problem as me. If you are unit testing your code, add the lib file also to your test target.

查看更多
登录 后发表回答