Problems With SQLite

This is a discussion on Problems With SQLite within the C++ Programming forums, part of the General Programming Boards category; New to SQLite. Copied a program from a tutorial site to test whether it is working or not! Code: #include ...

  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
    2,553
    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.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  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, 09: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, 03:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21