使用Sqlite出现undefined reference to `sqlite3_open'...

前端之家收集整理的这篇文章主要介绍了使用Sqlite出现undefined reference to `sqlite3_open'...前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
假设你已经正确编译和安装了sqlite,写个测试程序来测试: #include <stdlib.h> #include <stdio.h> #include "sqlite3.h" int main(void) { sqlite3 *db=NULL; char *zErrMsg = 0; int rc; rc=sqlite3_open("test1.db",&db); if(rc) { fprintf(stderr,"Can't open database: %s\n",sqlite3_errmsg(db)); sqlite3_close(db); exit(1); } else printf("open mydata successfully!\n"); sqlite3_close(db); return 0; } 用GCC来编译的时候总是会出现错误,编译的命令如下 gcc -static -o hello -lsqlite3 -L /usr/local/lib -I/usr/local/include hello.c 错误信息如下 /tmp/ccKeKpX9.o(.text+0x37): In function `main': : undefined reference to `sqlite3_open' /tmp/ccKeKpX9.o(.text+0x51): In function `main': : undefined reference to `sqlite3_errmsg' /tmp/ccKeKpX9.o(.text+0x73): In function `main': : undefined reference to `sqlite3_close' /tmp/ccKeKpX9.o(.text+0x9b): In function `main': : undefined reference to `sqlite3_close' collect2: ld returned 1 exit status 那么,恭喜你中招了。错误根本不在sqlITE也不在你的程序,而在GCC。Gcc的编译参数是有顺序的。正确的编译命令是: gcc -o hello -L /usr/local/lib -I/usr/local/include -static hello.c -lsqlite3 说实话,这么的一个小问题困扰了我一天的时间!真是菜啊~~~~~~

猜你在找的Sqlite相关文章