开发者

Symbols like _sqlite3_open not found error

开发者 https://www.devze.com 2022-12-17 03:22 出处:网络
Hi I am getting this eror: Undefined symbols: \"_sqlite3_open\", referenced from: _main in ccRlWVer.o \"_sqliite3_close\", referenced from:

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;


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/build command.


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


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 =)

0

精彩评论

暂无评论...
验证码 换一张
取 消