xcode c++ sqlite3 symbol(s) not found for architecture x86_64

5.5k views Asked by At

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;
}
4

There are 4 answers

1
ash On

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.

0
user2725590 On

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

0
peterDriscoll On

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

1
Vinod Joshi On

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

#import <sqlite3.h>

enter image description here