SOLUTION: I just added -lpthread -ldl
flags to my makefile and it works! Have no idea why, but I'm lucky enough to avoid compiling of sqlite3 by hand as I was trying.. Hmm, anyway some answers where pretty good. Thanks guys, will go and drink some tea for you.
Three months ago I was able to find how to do that but now it is not working. I have a huge C++ app, where I need to embed the sqlite3 code, but I can't compile it. I use something like this:
gcc sqlite3.c -lpthread -ldl -o ./sqlite3.o
But it does not work; I have tried a lot of variations. I have a makefile, where I added sqlite3.h and sqlite3.c files. When I do make && make install
in my app's particular folder, it shows errors:
.libs/sqlite3.o: In function `pthreadMutexTry':
/home/.../client/sqlite3.c:17769: undefined reference to `pthread_mutex_trylock'
.libs/sqlite3.o: In function `pthreadMutexAlloc':
/home/.../client/sqlite3.c:17637: undefined reference to `pthread_mutexattr_init'
/home/.../client/sqlite3.c:17638: undefined reference to `pthread_mutexattr_settype'
/home/.../client/sqlite3.c:17640: undefined reference to `pthread_mutexattr_destroy'
This means that I need to add the -lpthread
flag, when trying to compile sqlite3 separately from the app. Well, I am stuck.
The order of the libraries on the command line when linking matters. Put the libraries (
-lpthread -ldl
) last.You need
-c
flag to produce an object file and not link. And skip the libraries — you pass them when linking the entire application.