Daniel Larkin wrote:
Hi all,
Hi there.
I've been playing around with SQLite through the command line
interface and with php and am very impressed. I'm now trying to use
sqlite with C++ but am running into a small problem when linking.
Firstly I'm using SQLite 2.8, which I compiled from source and this is
located in ~user_account/sqlite
(Sidenote: Any particular reason for using the ancient and no longer
supported 2.x line instead of the current 3.x line?)
My trivial test C program is as follows:
#include <string>
#include <iostream>
#include "sqlite.h"
using namespace std;
typedef struct sqlite sqlite;
int main(void){
const char *DbFilename;
DbFilename = "test.db";
cout <<"test:"<<DbFilename<<endl;
char *ErrMsg = 0;
static sqlite *db = 0;
db = sqlite_open(DbFilename, 0, &ErrMsg);
sqlite_close(db);
return 1;
}
I'm trying to compile this as follows:
g++ test_sqlite.cpp -Wall -I/<user_account>/sqlite/include/ -o test
But I get an undefined reference to sqlite_open and sqlite_close. I
think this is because it needs some sqlite library? So I tried:
g++ test_sqlite.cpp -Wall -I/<user_account>/sqlite/include/
-l/<user_account>/sqlite/lib/libsqlite.so -o test (btw if the
font isn't clear thats "capital i" and "little L" I'm using for the
include directory and the library directory)
-l specifies the library name, but you shouldn't use it like this.
Instead, provide a library search path using the -L (capital L) option,
similar to the include path -I, and provide the library base name using
-l (small L). The above compile and link command should read:
g++ test_sqlite.cpp -Wall -I/<user_account>/sqlite/include/
-L/<user_account>/sqlite/lib -lsqlite -o test
The argument to -l (small L) will automatically have "lib" prepended and
".so" appended by the linker driver.
HTH,
Mihai
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users