2011-07-20 48 views
2

這是我第一次在C. im的項目中工作,只是想創建一個SSH客戶端。libssh2 C編譯

我的代碼libssh2網站

http://www.libssh2.org/examples/ssh2.html

複製但是當我運行此我得到下面的錯誤?

main.o: In function `main': 
main.c:(.text+0xbe): undefined reference to `libssh2_init' 
main.c:(.text+0x1a7): undefined reference to `libssh2_session_init_ex' 
main.c:(.text+0x1bf): undefined reference to `libssh2_session_startup' 
main.c:(.text+0x209): undefined reference to `libssh2_hostkey_hash' 
main.c:(.text+0x282): undefined reference to `libssh2_userauth_list' 
main.c:(.text+0x3e3): undefined reference to `libssh2_userauth_password_ex' 
main.c:(.text+0x443): undefined reference to `libssh2_userauth_keyboard_interactive_ex' 
main.c:(.text+0x4b9): undefined reference to `libssh2_userauth_publickey_fromfile_ex' 
main.c:(.text+0x529): undefined reference to `libssh2_channel_open_ex' 
main.c:(.text+0x58d): undefined reference to `libssh2_channel_setenv_ex' 
main.c:(.text+0x5d9): undefined reference to `libssh2_channel_request_pty_ex' 
main.c:(.text+0x633): undefined reference to `libssh2_channel_process_startup' 
main.c:(.text+0x674): undefined reference to `libssh2_channel_free' 
main.c:(.text+0x6a0): undefined reference to `libssh2_session_disconnect_ex' 
main.c:(.text+0x6ac): undefined reference to `libssh2_session_free' 
main.c:(.text+0x6c9): undefined reference to `libssh2_exit' 
collect2: ld returned 1 exit status 

我知道有一些庫連接問題。我使用Netbeans作爲我的IDE,並且相對比較新。任何人都可以請指導我。我在互聯網上搜索了很多,但大多數回覆與使用gcc在命令中編譯的代碼有關。如果有人可以幫助Netbeans。

回答

2

明白了,在Netbeans的轉到文件 - >項目屬性 - >鏈接器 - >附加的命令我寫-lssh2

0

要編譯該代碼,您需要在系統中安裝libssh2。那些未定義的引用來自包含在頭文件中(並在代碼中使用)的函數,這些函數需要鏈接到實現它們的庫。

#include <libssh2.h> 
#include <libssh2_sftp.h> 

安裝libssh2後,您必須將標誌-lssh2添加到編譯器。我不知道Netbeans,所以我無法幫助你。瀏覽項目選項並查找有關編譯器參數/標誌的內容。

+0

libssh2已安裝。你的方法在命令行上工作。仍然無法弄清netbeans –

+0

我也想知道-lssh2的邏輯是什麼?我的意思是你怎麼知道這個關鍵字。 –

+0

因爲它是libssh2。編譯器標誌是-l後面跟着沒有'lib'的lib名稱。例如,如果你想包含數學庫(libm),你可以添加標誌-lm – nmat