sqlite3 in dev-c++

Dec 31, 2008 at 3:24am
Hi, I've been searching for days now and I still can't seem to find out how to do the following:
I am creating a simple program that needs to make a simple sql query for an entry for exaple:
SELECT * FROM TABLE1 WHERE PRODUCT_ID=USERCHOICE
I've tried using the sqlite3.h file that sqlite distributes and I keep getting a linker error:
[Linker error] undefined reference to `sqlite3_open'
[Linker error] undefined reference to `sqlite3_errmsg'
[Linker error] undefined reference to `sqlite3_close'
[Linker error] undefined reference to `sqlite3_exec'
[Linker error] undefined reference to `sqlite3_close'

I got this when trying to compile a sample program just to get the ball rolling, here is the sample program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <stdlib.h>
#include "sqlite3.h"


    static int callback(void *NotUsed, int argc, char **argv, char **azColName){
      NotUsed=0;
      int i;
      for(i=0; i<argc; i++){
        printf("%s = %s\n", azColName[i], argv[i] ? argv[i]: "NULL");
      }
      printf("\n");
      return 0;
    }

    int main(int argc, char **argv){
      sqlite3 *db;
      char *zErrMsg = 0;
      int rc;

      if( argc!=3 ){
        fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
        exit(1);
      }
      rc = sqlite3_open(argv[1], &db);
      if( rc ){
        fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
        sqlite3_close(db);
        exit(1);
      }
      rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
      if( rc!=SQLITE_OK ){
        fprintf(stderr, "SQL error: %s\n", zErrMsg);
        /* This will free zErrMsg if assigned */
        if (zErrMsg)
           free(zErrMsg);
      }
      sqlite3_close(db);
      return 0;
    }

Any help would be greatly appreciated. Thanks alot
Dec 31, 2008 at 3:53am
What IDE/compiler?
Jan 4, 2009 at 6:56pm
@Helios: Read the title.

You will need to link the .a or .lib associated with that library with your project. You can do this by going to Project -> Options and then adding the file to the linker tab.
Jan 5, 2009 at 9:15am
The easiest way to use sqlite3 is to download the amalgamated source code (all the code in a single C file) and include that in your project. It works across Windows and POSIX platforms. This way you don't need to worry about libraries or dependencies or any such distractions.
Topic archived. No new replies allowed.