2017-01-23 84 views
0

這裏是我的包括:克++未定義參考libscrypt_scrypt(連接參數不是問題?)

#include <iostream> 
#include <string> 
#include <cstring> 
#include <stdio.h> //for snprintf 
#include <libscrypt.h> 
#include <sqlite3.h> 
#include "generator.h" //has no dependencies 

這是我的G ++ 4.2.1命令編譯錯誤:

# g++ -I/usr/local/include -L /usr/local/lib test.cpp generator.cpp -o test -lscrypt -lsqlite3 
/tmp//cctxmw4C.o: In function `insertUser()': 
test.cpp:(.text+0x607): undefined reference to `libscrypt_salt_gen(unsigned char*, unsigned long)' 
test.cpp:(.text+0x6c3): undefined reference to `libscrypt_scrypt(unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned long long, unsigned int, unsigned int, unsigned char*, unsigned long)' 
collect2: ld returned 1 exit status 

類似的C代碼編譯用GCC罰款。 我不認爲參數的順序是問題 - 我嘗試過多種變體,包括移動-I,-L和-l標誌。 scrypt和sqlite3都是C庫,儘管頭文件和共享庫分別位於-I和-L,sqlite3仍不會引發錯誤。

回答

1

看看這裏的解決方案。

Using C Libraries for C++ Programs

 

    extern "C"{ 
    void c_function_prototype(); 
    } 

 

    extern "C" void c_function_prototype(); 

If you have it see "The C++ Programming Language (Stoustrup) 4th Edition" p429 
+0

抱歉,但我不能發表評論(在主要問題),但... – ccpgh

+0

哇哦,我沒有任何線索。用extern「C」{...}封裝我的#include的首選方式,還是有一種不太麻煩的方式? – Saustin

+1

是的。已添加到我的回答 – ccpgh