我正在使用 Linux Mint 15。我sqlite-amalgamation-3080002.zip
从http://www.sqlite.org/download.html下载(并将文件放在我的项目目录中)
我已经完成了(即使我知道这对上一步来说是多余的):
sudo apt-get install sqlite3
sudo apt-get install libsqlite3-dev
sqlite3
在命令行下工作得很好,我可以创建/编辑数据库。
我创建了一个测试文件:
#include <stdio.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);
}
并跑:
gcc ./sqliteTest.c -o sqliteTest -lsqlite
并得到以下错误:
./sqliteTest.c: In function ‘main’:
./sqliteTest.c:14:7: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
/usr/bin/ld: cannot find -lsqlite
collect2: error: ld returned 1 exit status
我试过了:
gcc -Wall sqliteTest.c -o sqliteTest -lsqlite
并得到:
sqliteTest.c: In function ‘main’:
sqliteTest.c:14:7: warning: implicit declaration of function ‘exit’ [-Wimplicit-function-declaration]
sqliteTest.c:14:7: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
sqliteTest.c:7:10: warning: unused variable ‘zErrMsg’ [-Wunused-variable]
sqliteTest.c:19:1: warning: control reaches end of non-void function [-Wreturn-type]
/usr/bin/ld: cannot find -lsqlite
collect2: error: ld returned 1 exit status
我更改<sqlite3.h>
为"sqlite3.h"
并执行了第一个编译命令并得到:
./sqliteTest.c: In function ‘main’:
./sqliteTest.c:14:7: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
/tmp/ccvdOOv2.o: In function `main':
sqliteTest.c:(.text+0x24): undefined reference to `sqlite3_open'
sqliteTest.c:(.text+0x39): undefined reference to `sqlite3_errmsg'
sqliteTest.c:(.text+0x89): undefined reference to `sqlite3_close'
collect2: error: ld returned 1 exit status
我很难过......接下来我该怎么做?