Thread: Problems With SQLite

  1. #1
    Infant of C
    Join Date
    May 2010
    Location
    Karachi, Pakistan
    Posts
    118

    Problems With SQLite

    New to SQLite. Copied a program from a tutorial site to test whether it is working or not!
    Code:
    #include <iostream>
    #include <sqlite3.h>
    #include <stdlib.h>
    
    // g++ AccessTableEmployee.cpp -lsqlite3
    
    using namespace std;
    
    static int callback(void *NotUsed, int argc, char **argv, char **azColName)
    {
      int i;
      cout << "Number of args= " << argc << endl;
    
      for(i=0; i<argc; i++)
      {
         cout << azColName[i] << " = " << (argv[i] ? argv[i] : "NULL") << endl;
      }
      cout << endl;
      return 0;
    }
    
    int main(int argc, char **argv)
    {
      sqlite3 *db;       // Declare pointer to sqlite database structure
      char *zErrMsg = 0;
    
      // Open Database 
    
      int rc = sqlite3_open("Try.db", &db);
      if( rc )
      {
        cerr << "Can't open database: " << sqlite3_errmsg(db) << endl;
        sqlite3_close(db);
        exit(1);
      }
      // Select from database 
    
      rc = sqlite3_exec(db,"select * from emp", callback, 0, &zErrMsg);
      if( rc!=SQLITE_OK )
      {
          cerr << "SQL error: " << zErrMsg << endl;
          sqlite3_free(zErrMsg);
      }
    
      // Close
    
      sqlite3_close(db);
      return 0;
    }
    compiled using following command

    g++ -o SQL SQLite.cpp

    I am getting following error

    /tmp/ccxSqt2x.o: In function `main':
    SQLTry.cpp: (.text+0xfd): undefined reference to `sqlite3_open'
    SQLTry.cpp: (.text+0x114): undefined reference to `sqlite3_errmsg'
    SQLTry.cpp: (.text+0x152): undefined reference to `sqlite3_close'
    SQLTry.cpp: (.text+0x18a): undefined reference to `sqlite3_exec'
    SQLTry.cpp: (.text+0x1d5): undefined reference to `sqlite3_free'
    SQLTry.cpp: (.text+0x1e1): undefined reference to `sqlite3_close'
    collect2: ld returned 1 exit status

    googled for the solution and came across the same solution every where in the from of following command

    g++ -o SQL -lsqlite3 SQLite.cpp

    But this solution is not working with me!
    Any Help Appreciated!

    Using GCC on Debian Linux...

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Have you tried linking to the library sqlite3 as your Google results show?

    The command you used
    Code:
    g++ -o SQL SQLite.cpp
    The normal way to link to the library
    Code:
    g++ -o SQL SQLite.cpp -lsqlite3
    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Infant of C
    Join Date
    May 2010
    Location
    Karachi, Pakistan
    Posts
    118
    Urgh
    I am soooooo silly!

    Thank You A Lot!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SQLite in C
    By bluechip in forum C Programming
    Replies: 2
    Last Post: 10-14-2012, 12:32 PM
  2. MinGW and SQLite
    By CarlGB in forum C Programming
    Replies: 5
    Last Post: 02-15-2010, 10:30 PM
  3. SQLite questions
    By ac251404 in forum C++ Programming
    Replies: 6
    Last Post: 08-22-2006, 11:00 AM
  4. How to using SQLite with WINAPI
    By nostromos in forum Windows Programming
    Replies: 1
    Last Post: 10-02-2005, 01:53 AM
  5. Using SQLite?
    By IM! in forum C++ Programming
    Replies: 18
    Last Post: 03-16-2005, 04:00 AM