0

Hi I want to use sqlite in c++ project in xcode 4

now i am getting this error

Ld /Users/jayb/Library/Developer/Xcode/DerivedData/EMS-bpigynlzjbrescadebhoiupqmtkg/Build/Products/Debug/EMS normal x86_64 cd /Users/jayb/Documents/Developement/EMS/EMS setenv MACOSX_DEPLOYMENT_TARGET 10.8 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/jayb/Library/Developer/Xcode/DerivedData/EMS-bpigynlzjbrescadebhoiupqmtkg/Build/Products/Debug -F/Users/jayb/Library/Developer/Xcode/DerivedData/EMS-bpigynlzjbrescadebhoiupqmtkg/Build/Products/Debug -filelist /Users/jayb/Library/Developer/Xcode/DerivedData/EMS-bpigynlzjbrescadebhoiupqmtkg/Build/Intermediates/EMS.build/Debug/EMS.build/Objects-normal/x86_64/EMS.LinkFileList -mmacosx-version-min=10.8 -o /Users/jayb/Library/Developer/Xcode/DerivedData/EMS-bpigynlzjbrescadebhoiupqmtkg/Build/Products/Debug/EMS

Undefined symbols for architecture x86_64: "_sqlite3_close", referenced from: _main in main.o "_sqlite3_errmsg", referenced from: _main in main.o "_sqlite3_open", referenced from: _main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

and i found that is linker problem it may fix with compiler option -lsqlite3

but, how can i add that option in Xcode??????

I use "Run" button on xcode 4.4 to compile my project. i am not compiling in terminal window.

this is my code

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <sqlite3.h>

using namespace std;

int main()
{   
    sqlite3 *db;
    int rc = sqlite3_open("EMSDB", &db);
    if (rc) {
        fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
        exit(0);
    }
    else {
        fprintf(stderr, "Opened Database successfully\n");
    }

    sqlite3_close(db);

    return 0;
}
user2725590
  • 61
  • 1
  • 3

4 Answers4

6

I found the way, wish it helps someone looking for the same solution. now it builds correct and i can see the output

woops, I cannot post image yet :(

from the xcode build settings, you can find a tab called (Linking) and on the Linking tab there are field call 'Other Linker Flags' i simply added the -lsqlite3 for both Debug, and Release

cheers

user2725590
  • 61
  • 1
  • 3
6

I was getting the similar error : I did following in my case:

#import <sqlite3.h>

enter image description here

Vinod Joshi
  • 7,696
  • 1
  • 50
  • 51
  • You are a genius, you have NO IDEA how long I’ve been trying to compile SQLite3 with C++, WEEKS man — their site is USELESS, I’ve tried Linux windows Mac and was about done trying. THANK you! – Zach Oakes Aug 12 '19 at 21:33
1

I am not familiar with xcode. Look for linker settings or compiler settings and add the -lsqlite3 there.

Perhaps this page helps: Xcode what's the difference between "Other Linker Flags" vs "Other_LDFLAGS"

LDFLAGS are passed to the linker. CFLAGS are passed to the compiler.

Community
  • 1
  • 1
ash
  • 4,867
  • 1
  • 23
  • 33
  • Thank you for the information, If anyone know how to do that in Xcode 4.3 enviroment, would be much appriciated – user2725590 Aug 28 '13 at 23:07
0

It is require to link libsqlite3.dylib in your project. That can be done in Linked Frameworks and Libraries and add libsqlite3.dylib.

for reference follow: xcode sqlite3 libsqlite.dylib

Community
  • 1
  • 1
peterDriscoll
  • 377
  • 4
  • 8