Reputation: 9473
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?
Upvotes: 37
Views: 56315
Reputation: 11
Devcpp
1. add sqlite3.dll
file in the project folder.
2. go to Compiler option in Tools >>
3. write sqlite3.dll
next to >> Add the following commands when calling compiler
NOTE : install MinGW (compiler)
g++ file.cpp -o output.exe sqlite3.dll
define sqlite3.dll
in linker in project properties
Upvotes: 0
Reputation: 21
First step: Install all library sqlite3 with the command:
sudo apt-get install libsqlite3-dev
With that you can use #include <sqlite3.h>
in a programm of C
or C++
.
Second step: To compile the program by console:
C++:
g++ program.cpp -o executable -lsqlite3
./executable
C:
gcc program.c -o executable -lsqlite3
./executable
Upvotes: 2
Reputation: 1
Either link your program to lib g++ yourProgram.c -lsqlite3 in command line or in Open IDE -> project -> properties -> locate lib file for sqlite3 .
Upvotes: 0
Reputation: 976
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 the g++
command:
g++ main.cpp sqlite3.c
as per: http://sqlite.org/cvstrac/wiki?p=HowToCompile
Upvotes: 8
Reputation: 70701
You need to link the sqlite3 library along with your program:
g++ main.cpp -lsqlite3
Upvotes: 57