2012-04-15 39 views
1

我試圖在ubuntu上手動鏈接外部庫與C++。由於這是我的第一個C++項目,我錯過了一些基礎知識。 這是我的代碼(這個嘗試連接到傳播):如何在Ubuntu上手動鏈接g ++的庫

#include <iostream> 
#include <sp.h> 

using namespace std; 

int main() { 
    int status; 
    status = SP_connect("[email protected]", "test1", 0, 0, 0, 0); 
    cout << "done\n"; 
    return 0; 
} 

如果我只是嘗試,據我瞭解,我需要鏈接庫

[email protected]:~/thesis$ g++ -o example1 test.cpp 
/tmp/cczPLZQ0.o: In function `main': 
test.cpp:(.text+0x39): undefined reference to `SP_connect' 
collect2: ld returned 1 exit status 

運行它,我試着與-l

[email protected]:~/thesis$ g++ -o example1 test.cpp -llibspread 
/usr/bin/ld: cannot find -llibspread 
collect2: ld returned 1 exit status 

我也試過這個(我拍攝黑暗這裏)做到這一點:

[email protected]:~/thesis$ g++ -o example1 test.cpp $(pkg-config -cflags /usr/local/lib/libspread) $(pkg-config --libs /usr/local/lib/libspread) 

-cflags: unknown option 
Package /usr/local/lib/libspread was not found in the pkg-config search path. 
Perhaps you should add the directory containing `/usr/local/lib/libspread.pc' 
to the PKG_CONFIG_PATH environment variable 
No package '/usr/local/lib/libspread' found 
/tmp/ccU8GTC2.o: In function `main': 
test.cpp:(.text+0x39): undefined reference to `SP_connect' 
collect2: ld returned 1 exit status 

任何幫助,將不勝感激。

+6

如果.so文件位於標準位置,「-lspread」將是正確的選項。 – Mat 2012-04-15 20:46:17

+1

您應該跳過-llibspread中的lib,只需使用-lspread – gulyan 2012-04-15 20:47:58

回答

1

由於@Mat表示您應該使用-lspread並省略前綴lib