kjh
kjh

Reputation: 3403

How to compile sqlite3.c in Fedora?

I'm having trouble building the sqlite3 amalgamation the same way I used to do it in windows, by compiling the source right into my program, here is my current makefile

all:
    gcc -g -c sqlite3.c -o sqlite3.o
    g++ -g -c main.cpp -o main.o
    g++ -o test sqlite3.o main.o

my main.cpp file:

#include "sqlite3.h"

int main(){
  //nothing
 return 0;
}

and here are the errors i receive when compiling:

sqlite.o: In function `pthreadMutexAlloc':
/home/kendal/c++/sqlite3/test/../lib/sqlite3.c:17910: undefined reference to
`pthread_mutexattr_init'
/home/kendal/c++/sqlite3/test/../lib/sqlite3.c:17911: undefined reference to
`pthread_mutexattr_settype'
/home/kendal/c++/sqlite3/test/../lib/sqlite3.c:17913: undefined reference to`pthread_mutexattr_destroy'
sqlite.o: In function    
`pthreadMutexTry':
/home/kendal/c++/sqlite3/test/../lib/sqlite3.c:18042: undefined reference to `pthread_mutex_trylock'
sqlite.o: In function `unixDlOpen': /home/kendal/c++/sqlite3/test/../lib/sqlite3.c:28164: undefined reference to `dlopen' 
sqlite.o: In function `unixDlError':
/home/kendal/c++/sqlite3/test/../lib/sqlite3.c:28178: undefined reference to `dlerror'
sqlite.o: In function `unixDlSym':
/home/kendal/c++/sqlite3/test/../lib/sqlite3.c:28204: undefined reference to `dlsym'
sqlite.o: In function `unixDlClose':
/home/kendal/c++/sqlite3/test/../lib/sqlite3.c:28209: undefined reference to `dlclose'

Upvotes: 3

Views: 2394

Answers (1)

mauve
mauve

Reputation: 2016

You must also link to pthreads and dl, do it like this:

all:
  gcc -g -c sqlite3.c -o sqlite3.o
  g++ -g -c main.cpp -o main.o
  g++ -o test -pthread -ldl sqlite3.o main.o

Using "-lpthread" is a bit different than using "-pthread", "-lpthread" means link against the pthread-library whereas "-pthread" means that g++ will choose the appropriate threading library with an pthread interface for you. That is the reason why you should prefer to use "-pthread".

Adding "-ldl" means you link to the "dl" library which is the library which contains dlsym, dlopen and so forth.

Upvotes: 8

Related Questions