I am working on Linux Mint 15. I downloaded sqlite-amalgamation-3080002.zip from http://www.sqlite.org/download.html (and put the files in the project directory)
I did (although I know that it is redundant in the previous step):
sudo apt-get install sqlite3 sudo apt-get install libsqlite3-dev
sqlite3 works fine on the command line, and I can create / edit databases.
I created a test file:
#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); }
and ran:
gcc ./sqliteTest.c -o sqliteTest -lsqlite
and got the following error:
./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
I tried:
gcc -Wall sqliteTest.c -o sqliteTest -lsqlite
and received:
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
I changed <sqlite3.h> to "sqlite3.h" and "sqlite3.h" first compilation command and got:
./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
I'm at a dead end ... What should I do next?