On Fri, Sep 12, 2008 at 11:09 AM, Mihai Limbasan <[EMAIL PROTECTED]> wrote:
> 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

Thanks for the super fast response!  and for the clarification on how
I should be using the linker. My test program now compiles and links,
but when I try to run it I get a run time error saying"

"test: error while loading shared libraries: libsqlite.so.0: cannot
open shared object file: No such file or directory"


I double checked that the libsqlite.so.0 exists in the given directory
and it does, so am not sure why I'm getting this message?

Incidentally I'm using version 2.8 because I ultimately want to create
a little application that uses c++ and displays results in a php
website, but sqlite3 doesn't seem to be supported in the local
installed version of php with apache on my server and I don't have
root access to address this, whilst sqlite version 2.8 seems to  work
with php/apache on my webserver.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to