0

I know there have been questions asked before about this problem but none seem to shine a light on my problem which is, I am trying to compile a C application and want to access SQLite from within the code (as per test app below) using Eclips as a compile and debugging environment.

I know the .h files are being accessed. the code has as many lines commented out to do with iostream as I have tried to compile this as a C++ app as well.

I get errors one for each of 2 the SQL API.

The real question is do I have to set and How do I set a dependency in Eclipse to allow the api to resolve. Thanks

the code

#include <sqlite3.h>

int main()
{
    int RetVal;
    RetVal = OpenDB();
    return RetVal;
}

int OpenDB()
{
    sqlite3 *db;         // database connection
    int rc;              // return code
    char *errmsg;        // pointer to an error string

     /*
      * open SQLite database file test.db
      * use ":memory:" to use an in-memory database
      */
     rc = sqlite3_open(":memory:", &db);  //fails on this line
     if (rc != SQLITE_OK)
        {
        goto out;
        }


/* use the database... */

out:
/*
 * close SQLite database
 */
sqlite3_close(db); //fails on this line
return 0;
}
alk
  • 69,737
  • 10
  • 105
  • 255
John
  • 1
  • 4
  • 3
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – m.s. Jan 04 '17 at 10:31
  • 1
    Tell Eclipse to tell the compiler to tell the linker to link the appropriate library. – alk Jan 04 '17 at 11:18
  • 1
    Assuming CDT, for the (somewhat outdated) Juno-Release it's under "Project->Properties->C/C++ Build->Settings->GCC Linker->Libraries" – alk Jan 04 '17 at 11:22
  • two things are needed to access the SQL lite functions: 1)at compile time, the appropriate header file must be available and `#include`d in the source code 2) at link time the appropriate library must be included via a `-L -l parameters (on the end) of the linker command line. – user3629249 Jan 05 '17 at 09:56

1 Answers1

0

You need to link the sqlite3 library along with your program:

gcc main.c -lsqlite3
Sumit Gemini
  • 1,836
  • 1
  • 15
  • 19