0
votes

I am trying to use Sqlite in my Netbeans C++ and following the tutorial here http://www.dreamincode.net/forums/topic/122300-sqlite-in-c/

When i build it,its giving me undefined reference to `sqlite3_open' and the other sqlite3 functions. I included the sqlite3.h too. What am i missing here?

When i added the linker to static library libsqlite3.a in project properties, my undefined reference errors are gone but now its giving me

/usr/lib/libsqlite3.a(sqlite3.o): In function pthreadMutexTry': /usr/lib/libsqlite3.a(sqlite3.o): In functionpthreadMutexAlloc': /usr/lib/libsqlite3.a(sqlite3.o): In function pthreadMutexAlloc': /usr/lib/libsqlite3.a(sqlite3.o): In functionpthreadMutexAlloc': /usr/lib/libsqlite3.a(sqlite3.o): In function unixDlError': /usr/lib/libsqlite3.a(sqlite3.o): In functionfindLockInfo': /usr/lib/libsqlite3.a(sqlite3.o): In function findLockInfo': /usr/lib/libsqlite3.a(sqlite3.o): In functionunixDlSym': /usr/lib/libsqlite3.a(sqlite3.o): In function unixDlClose': /usr/lib/libsqlite3.a(sqlite3.o): In functionunixDlOpen': collect2: ld returned 1 exit status make[2]: * [dist/Debug/GNU-Linux-x86/cddb] Error 1 make[1]: * [.build-conf] Error 2 make: *** [.build-impl] Error 2

And if i include the sqlite3ext.h, I get main.cpp:20: error: ‘sqlite3_api’ was not declared in this scope

2

2 Answers

2
votes

(please see EDIT below)

Not sure how C++ works in NetBeans, but your adding libsqlite3.a looks pretty good. Now if you have a Makefile you could edit it and define (or edit) the LDFLAGS variable, and pass it as an option to the linker...

SQLite in its default configuration needs to link with libdl and libpthread, that is why you might need to add -ldl -lpthread to your linking options.

For instance (if this is possible in NetBeans) add this to your Makefile :

LDFLAGS= -ldl -lpthread

In my projects I use it like so :

target: $(OBJ)
    gcc $(LDFLAGS)  $(OBJ) -o $@

EDIT :

Actually it is also possible to add linker options in the GUI, without editing the Makefile by hand :

In submenu Configuration Properties -> Linker -> Command Line, just add -ldl -lpthread in "Additional options" and recompile your project.

1
votes

Integrating Sqlite into Netbeans on Linux
1)Synaptic Package Manager - Install libsqlite3-dev
2)Netbeans->Your_Project Properties->Linker->Libraries->Add Library-> libsqlite3.a
3)#include sqlite3.h
It works!