2012-04-15 11 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 

でそれを実行しようとすると、私が試しました(私はここに暗闇の中で撮影しています)私もこれを試してみました

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

-lでそれを行うには:

[email protected]puter:~/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

+1

-libreadのlibをスキップして、-lspreadを使用するだけです。 – gulyan

答えて

1

@Matによると、-lspreadを使用し、接頭辞libは省略してください。

関連する問題