Suppose you have compiled and installed SQLite correctly, and write a test.ProgramTo test:
# 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;
}
Errors always occur when compiling with GCC. The compilation command is as follows:
Gcc-static-O hello-lsqlite3-L/usr/local/lib-I/usr/local/include hello. c
The error message is as follows:
/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
Congratulations. The error is not in SQLite or your program, but in GCC. GCC compilation parameters are sequential. The correct compilation command is:
Gcc-O hello-L/usr/local/lib-I/usr/local/include-static hello. C-lsqlite3
To be honest, such a small problem has plagued me for a day! Really ~~~~~~