【发布时间】:2018-08-02 11:52:28
【问题描述】:
我遇到了一个问题,我无法编译使用 libssh 的 ssh 客户端。 这摘自 Wil Allsopp 书。
#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
int main()
{
ssh_session my_ssh_session;
int rc;
char *password;
my_ssh_session = ssh_new();
if (my_ssh_session == NULL)
exit(-1):
ssh_options_set(my_ssh session, SSH_OTIONS_HOST, "c2host");
ssh_options_set(my_ssh_session, SSH_OTIONS_PORT, 443);
ssh_options_set(my_ssh_session, SSH_OTIONS_PORT, "c2user");
rc = ssh_connect(my_ssh_session);
if (verify_knownhost(my_ssh_session) < 0)
{
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
exit(-1)
}
password = ("Password");
rc = ssh_userauth_password(my_ssh_session, NULL, password);
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
}
我试过这个命令,但没有帮助:
gcc -I C:\MinGW\lib\gcc\mingw32\6.3.0\include\libssh\ -L C:\MinGW\lib\gcc\mingw32\6.3.0\include\libssh -lssh ssh.c -o out.exe
我收到此错误:
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: 找不到 -lssh collect2.exe:错误:ld 返回 1 个退出状态
有什么想法吗?谢谢!
我猜这个库是通过以下命令找到的,但是我得到了这个错误:
gcc -I C:\MinGW\lib\gcc\mingw32\6.3.0\include\libssh\ -L
C:\MinGW\lib\gcc\mingw32\6.3.0\lib\ -lssh ssh.c -o out.exe
ssh.c:在函数'main'中: ssh.c:35:52:警告:传递 'ssh_options_set' 的参数 3 使指针从整数而不进行强制转换 [-Wint-conversion] ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, 443); ^~~ 在 ssh.c:19:0 包含的文件中: c:\mingw\lib\gcc\mingw32\6.3.0\include\libssh\libssh.h:495:16: 注意:预期为 'const void *' 但参数类型为 'int' LIBSSH_API int ssh_options_set(ssh_session session, enum ssh_options_e type, ^~~~~~~~~~~~~~~ C:\Users\matteo\AppData\Local\Temp\ccI0eQk0.o:ssh.c:(.text+0xf): 未定义引用
_imp__ssh_new' C:\Users\AppData\Local\Temp\ccI0eQk0.o:ssh.c:(.text+0x44): undefined reference to_imp__ssh_options_set' C:\Users\AppData\Local\Temp\ccI0eQk0.o:ssh.c:(.text+0x62): 未定义引用_imp__ssh_options_set' C:\Users\AppData\Local\Temp\ccI0eQk0.o:ssh.c:(.text+0x80): undefined reference to_imp__ssh_options_set' C:\Users\AppData\Local\Temp\ccI0eQk0.o:ssh.c:(.text+0x8e): 未定义引用_imp__ssh_connect' C:\Users\AppData\Local\Temp\ccI0eQk0.o:ssh.c:(.text+0xb8): undefined reference to_imp__ssh_userauth_password' C:\Users\AppData\Local\Temp\ccI0eQk0.o:ssh.c:(.text+0xca): 未定义引用_imp__ssh_disconnect' C:\Users\AppData\Local\Temp\ccI0eQk0.o:ssh.c:(.text+0xd8): undefined reference to_imp__ssh_free' collect2.exe:错误:ld 返回 1 个退出状态
【问题讨论】:
-
-LC:\MinGW\lib\gcc\mingw32\6.3.0\include\libssh 应该是:-LC:\MinGW\lib\gcc\mingw32\6.3.0\lib\libssh
-
你找到答案了吗?