Connecting Tech Pros Worldwide Forums | Help | Site Map

Sqlite3 and C++

Member
 
Join Date: May 2007
Posts: 120
#1: Jul 6 '09
I am trying to just do a test of sqlite3 and C++ but I having touble.

I am compiling on Mac OS X.


Program:
<code>

#include <iostream>
using namespace std;

#include <sqlite3.h>
sqlite3* db;
char* db_err;

int main() {
sqlite3_open("testDB.sql", &db);
sqlite3_exec(db, "create table 'helloworld' (id integer);", NULL, 0, &db_err);
sqlite3_close(db);
}
</code>



Output:

**** Build of configuration Debug for project HelloWorld ****

make all
Building file: ../src/HelloWorld.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/HelloWorld.d" -MT"src/HelloWorld.d" -o"src/HelloWorld.o" "../src/HelloWorld.cpp"
Finished building: ../src/HelloWorld.cpp

Building target: HelloWorld
Invoking: MacOS X C++ Linker
g++ -o "HelloWorld" ./src/HelloWorld.o
Undefined symbols:
"_sqlite3_open", referenced from:
_main in HelloWorld.o
"_sqlite3_close", referenced from:
_main in HelloWorld.o
"_sqlite3_exec", referenced from:
_main in HelloWorld.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [HelloWorld] Error 1
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Jul 7 '09

re: Sqlite3 and C++


There must be a sqllite3 library somewhere; feed that to your linker in the last stage of the build; check your manuals how to do that.

kind regards,

Jos
RedSon's Avatar
Site Moderator
 
Join Date: Jan 2007
Location: America
Posts: 3,393
#3: Jul 9 '09

re: Sqlite3 and C++


There is no library for SQLite if you are using the SQLite amalgamation file. You must add SQLite.c to your build so that the symbols are created properly. Your linker is complaining that it doesnt know what "_sqlite3_open", "_sqlite3_exec" and "_sqlite3_close" mean.
Member
 
Join Date: May 2007
Posts: 120
#4: Jul 10 '09

re: Sqlite3 and C++


Thanks all, I did get it working. I switched to a new IDE and thought they were linked but it wasnt.
Reply