libssh2 C 编译
这是我第一次使用 C 语言进行项目。我只是想制作一个 SSH 客户端。
我的代码从 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 上提供帮助。
Its my first time working on a project in C. im just trying to make a SSH client.
my code copied from libssh2 site
http://www.libssh2.org/examples/ssh2.html
But when i run this i get the following errors ?
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
I know there is some issue with library linking. Im using Netbeans as my IDE and am relatively new to this. Can anyone please guide me. I have searched a lot on the Internet, But mostly replies are related to code compiled on the command using gcc. If someone can help in Netbeans.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
明白了,在 Netbeans 中转到“文件”->“项目属性->链接器->我写的附加命令 -lssh2
Got it , in Netbeans goto File -> Project Properties -> Linker -> Additional Commands i wrote -lssh2
要编译该代码,您需要在系统中安装 libssh2。这些未定义的引用来自头文件中包含的函数(并在代码中使用),需要链接到实现它们的库。
安装 libssh2 后,您必须将标志 -lssh2 添加到编译器中。我不了解 Netbeans,所以我无法帮助您。浏览项目选项并查找有关编译器参数/标志的信息。
To compile that code you need to install libssh2 in your system. Those undefined references come from the functions included in the header files (and used in the code) that need to be linked to the library where they are implemented.
After installing libssh2 you must add the flag -lssh2 to the compiler. I don't know about Netbeans so I can't help you with that. Browse through the project options and look for something about the compiler parameters/flags.