Linker Error when trying to use Sqlite with GCC

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Linker Error when trying to use Sqlite with GCC

Michael Gaskins
I'm working on an application that will require an embedded database
backend and Sqlite is looking to be my prime choice here.

Now, I typically write the GUI and the working code seperately anyways
and tie them together later, so I figured I'd begin work on my backend
that talks with the database.  I've never actually done any previous
database programming so I'm learning as I go here :).

I'm having trouble getting my (very primitive) experimental program to
link however.  Below is my code for test.c:

#include <stdio.h>
#include <sqlite3.h>

int main (int argc, char **argv) {

  struct sqlite *pilotLog;
 
  pilotLog = sqlite_open("logbook.dat", 0, NULL);

  sqlite_close(pilotLog);

  return 0;
}

Now, with the following compiled command:

gcc -Wall -lsqlite3 test.c -o test

I get the following output:

test.c: In function `main':
test.c:9: warning: implicit declaration of function `sqlite_open'
test.c:9: warning: assignment makes pointer from integer without a cast
test.c:11: warning: implicit declaration of function `sqlite_close'
/tmp/ccg3BEWL.o(.text+0x28): In function `main':
: undefined reference to `sqlite_open'
/tmp/ccg3BEWL.o(.text+0x36): In function `main':
: undefined reference to `sqlite_close'
collect2: ld returned 1 exit status

I have verified that the library is there.  Normally I would assume that
I had something setup incorrectly, but I've repeated this on both a
completely up-to-date Gentoo Linux box and a FreeBSD 4.10 box, with the
same results.  Is there something obvious that I'm missing here? Thanks.

Mike Gaskins


Reply | Threaded
Open this post in threaded view
|

RE: Linker Error when trying to use Sqlite with GCC

Robert Simpson
> -----Original Message-----
> From: Michael Gaskins [mailto:[hidden email]]
> Sent: Tuesday, August 23, 2005 12:09 AM
> To: [hidden email]
> Subject: [sqlite] Linker Error when trying to use Sqlite with GCC
>
> I'm working on an application that will require an embedded
> database backend and Sqlite is looking to be my prime choice here.
>
> Now, I typically write the GUI and the working code
> seperately anyways and tie them together later, so I figured
> I'd begin work on my backend that talks with the database.  
> I've never actually done any previous database programming so
> I'm learning as I go here :).
>
> I'm having trouble getting my (very primitive) experimental
> program to link however.  Below is my code for test.c:
>
> #include <stdio.h>
> #include <sqlite3.h>
>
> int main (int argc, char **argv) {
>
>   struct sqlite *pilotLog;
>  
>   pilotLog = sqlite_open("logbook.dat", 0, NULL);
>
>   sqlite_close(pilotLog);
>
>   return 0;
> }
>

Try struct sqlite3 *, sqlite3_open(), sqlite3_close() instead -- you'll find
they work much better :)

Robert




Reply | Threaded
Open this post in threaded view
|

Re: Linker Error when trying to use Sqlite with GCC

Ulrik Sandborg-Petersen
In reply to this post by Michael Gaskins
Hi Michael,

Michael Gaskins wrote:

>I'm working on an application that will require an embedded database
>backend and Sqlite is looking to be my prime choice here.
>
>Now, I typically write the GUI and the working code seperately anyways
>and tie them together later, so I figured I'd begin work on my backend
>that talks with the database.  I've never actually done any previous
>database programming so I'm learning as I go here :).
>
>I'm having trouble getting my (very primitive) experimental program to
>link however.  Below is my code for test.c:
>
>#include <stdio.h>
>#include <sqlite3.h>
>
>int main (int argc, char **argv) {
>
>  struct sqlite *pilotLog;
>  
>  pilotLog = sqlite_open("logbook.dat", 0, NULL);
>
>  sqlite_close(pilotLog);
>  
>

How about using sqlite3_open and sqlite3_close ?


HTH

Ulrik P.

--
Ulrik Petersen, Denmark