工作需要,开始学习,第一个程序
#include<stdio.h> #include<stdlib.h> #include"sqlite3.h" int main(int argc,char *argv[]) { sqlite3 *db; char *zErrMsg = 0; int rc; rc = sqlite3_open("test.db",&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; }
错误原因 undefinede reference to sqlite3_open错误可能根本不在sqlITE也不在你的程序,而在GCC。Gcc的编译参数是有顺序的。正确的编译命令是:
cc -o testsql -L /home/sqlite-autoconf-3080300/sqlite_x86/lib/ -I /home/sqlite-autoconf-3080300/sqlite_x86/include/ testsql.c -lsqlite3
警告原因,则是因为,没有包含<stdlib.h>,
原文链接:https://www.f2er.com/sqlite/200621.html