12

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 Answers 4

59

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/

7
  • Okay, it compiled with your tip! Thank you!! However, the app doesn't work in the iPhone, as soon as it calls the method that uses sqlite3 library it breaks and closes the app. In the simulator works fine... Why this? Any idea? Humm... I added the libsqlite3.dylib from the default folder that the Xcode 4.1 shows..
    – Ibai
    Oct 2, 2011 at 16:33
  • On the device you should get a crash log (Organizer => Devices => Device Log)
    – ott--
    Oct 2, 2011 at 18:07
  • Hi ott. Well, I can't afford a Developer license, I'm starting in this iOS programming world as a hobby and as a student it's not possible for me that. I hope you understand. Do you have any idea of why could be this causing a crash? It compiles but not works... Thanks again
    – Ibai
    Oct 2, 2011 at 18:27
  • Without source code I can't tell much. You could put that method to pastebin.com or similar and tell me the url.
    – ott--
    Oct 2, 2011 at 19:21
  • 2
    For XCode 4.6, it is under: Project > Build Settings > Linking > Other Linker Flags, with the value "-lsqlite3"
    – phyatt
    Apr 8, 2013 at 6:28
2

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.

0

Did you try to import sqlite3 library like:

#import "sqlite3.h"

instead of:

#import <sqlite3.h>

0
-1

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.