I'm trying to get started with the C++ API for SQLite.
#include <iostream>
#include <sqlite3.h>
using namespace std;
int main()
{
sqlite3 *db;
if (sqlite3_open("ex1.db", &db) == SQLITE_OK)
cout << "Opened db successfully\n";
else
cout << "Failed to open db\n";
return 0;
}
Compiling this using the command "g++ main.cpp" gives the following error:
/tmp/ccu8sv4b.o: In function `main':
main.cpp:(.text+0x64): undefined reference to `sqlite3_open'
collect2: ld returned 1 exit status
What could have gone wrong? Hasn't sqlite3 properly installed in the server I'm compiling this in?
You need to link the sqlite3 library along with your program:
You need to adjust your linker flags to link in the
sqlite3
library. Libraries are usually installed in/usr/lib
or/usr/lib64
Alternatively, you can copy the
sqlite3.c
file to your project directory and compile it as part of theg++
command:as per: http://sqlite.org/cvstrac/wiki?p=HowToCompile