tags:

views:

84

answers:

3

Hi I am getting this eror:

Undefined symbols: "_sqlite3_open", referenced from: _main in ccRlWVer.o "_sqliite3_close", referenced from: _main in ccRlWVer.o "_sqlite3_exec", referenced from: _main in ccRlWVer.o "_sqlite3_errmsg", referenced from: _main in ccRlWVer.o "_sqlite3_close", referenced from: _main in ccRlWVer.o ld: symbol(s) not found collect2: ld returned 1 exit status

This is my code:

    const char * filename = "database.db";
sqlite3 * ppDb;
int rc;
rc = sqlite3_open(filename, &ppDb);
if( rc ){
    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(ppDb));
    sqlite3_close(ppDb);
    exit(1);
}

char * errMsg = 0;
sqlite3_exec(ppDb, sql ,display_result, 0, &errMsg);
if( rc!=SQLITE_OK ){
    fprintf(stderr, "SQL error: %s\n", errMsg);
}


sqliite3_close(ppDb);
return 0;

Thanks!

+1  A: 

Your code is not the problem, except the typo on the last line. The error you get, indicates that there is a problem when linking, specifically that the sqlite3_* symbols can't be resolved by the linker.

You probably need to specify the location of the sqlite library. If you expand your question with the commands you use for compiling, I can expand my answer =)

gnud
+3  A: 

You have to pass the library you wish to link your code with, in this situation it's sqlite3.

If you are using gcc try adding the:

-lsqlite3 

To your arguments you pass to gcc in your makefile/buildcommand.

Brian Gianforcaro
+1  A: 

It looks like the compiler can't find the sqlite library. Be sure to pass the -lsqlite3 flag when compiling (for gcc at least).

Kyle Lutz