sqlite3 + c++ error.

I'm trying to compile some c++ code that should access a small sql database. But everytime I try to use the sqlite.h library I get errors about the functions not existing. I looked directly at the sqlite.h file and they are defined so I should be getting diffrent errors. If anyone could shed some light on this that'd be great.

Here's the code I was trying to use.
Code:
#include <iostream>
#include "/usr/local/include/sqlite3.h"


int main(int argc, char **argv)
{
    sqlite3 *db;
    int rc;
    rc = sqlite3_open("/usr/home/halbersma/Devel/sql_test/testdb2.db", &db);
    if( rc == 1)
    {
          // error handling here

    }
    sqlite3_close(db);


    return 0;
}

and here's what happens when I try to compile

Code:
[halbersma@beastie /usr/home/halbersma/Devel/sql_test]$ c++ -g -o sql_test sql_test.cpp 
/var/tmp//cceBeiIg.o(.text+0x1c0): In function `main': /usr/home/halbersma/Devel/sql_test/sql_test.cpp:10: undefined reference to `sqlite3_open'
/var/tmp//cceBeiIg.o(.text+0x1ce):/usr/home/halbersma/Devel/sql_test sql_test.cpp:16: undefined reference to `sqlite3_close'
[halbersma@beastie /usr/home/halbersma/Devel/sql_test]$

Any thoughts would be awesome. Thanks.
 
You need to link against sqlite. Try to add `-lsqlite3 -L/usr/local/lib' at the end of your `c++' invocation.
 
Back
Top