2012-10-14 38 views
3
我無法建立sqlite3的合併我用來做什麼的窗口中以同樣的方式

,通過編譯源直接進入我的程序,這是我目前的makefile如何在Fedora中編譯sqlite3.c?

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

我的main.cpp文件:

#include "sqlite3.h" 

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

,這裏是編譯時我收到錯誤:

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' 

回答

8

您還必須鏈接到並行線程和DL,像這樣做:

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 

使用「-lpthread」比使用「-pthread」,「-lpthread」是指針對並行線程庫而「-pthread」鏈路的比特不同意味着克++將選擇具有適當的線程庫pthread接口爲你。這就是爲什麼你更喜歡使用「-pthread」的原因。

添加「-ldl」意味着您鏈接到「dl」庫,它是包含dlsym,dlopen等的庫。