像_sqlite3_open这样的符号没有找到错误

时间:2010-01-23 20:40:55

标签: c

您好我收到此错误:

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

这是我的代码:

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;

3 个答案:

答案 0 :(得分:12)

你必须传递你希望链接代码的库,在这种情况下它是sqlite3。

如果您正在使用gcc,请尝试添加:

-lsqlite3 

你的参数是你在makefile / build命令中传递给gcc的。

答案 1 :(得分:1)

您的代码不是问题,除了最后一行的拼写错误。您收到的错误表示链接时出现问题,特别是链接器无法解析sqlite3_*个符号。

您可能需要指定sqlite库的位置。如果使用用于编译的命令扩展问题,我可以扩展我的答案=)

答案 2 :(得分:1)

看起来编译器找不到sqlite库。编译时一定要传递-lsqlite3标志(至少为gcc)。