我正在遇到一个问题,即我无法编译使用 ssh client ,它使用 libsss> libssh 。这是从 wil allsopp book。
#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:MinGWlibgccmingw326.3.0includelibssh -L C:MinGWlibgccmingw326.3.0includelibssh -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:MinGWlibgccmingw326.3.0includelibssh -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'type'int' libssh_api int ssh_options_set(ssh_session会话,枚举ssh_options_e类型, ^~~~~~~~~~~~~~~ c: users matteo appdata local temp temp cci0eqk0.o:ssh.c :(。text 0xf(:
_imp__ssh_new' C:UsersAppDataLocalTempccI0eQk0.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:UsersAppDataLocalTempccI0eQk0.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:UsersAppDataLocalTempccI0eQk0.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:UsersAppDataLocalTempccI0eQk0.o:ssh.c:(.text+0xd8): undefined reference to
_imp__ssh_free' collect2.exe:错误:ld返回1退出状态
您应该保持清晰的头脑。在您编译了Libssh之后,您在这里有三个目录。lib,包括和bin。使用GCC与选项: -iinclude -llib -lssh 。这将告诉编译器包含您程序的目录和LIB目录。最后一个选项是告诉编译器您使用哪个文件。这应该取得成功。但是,您永远不知道这条路应该走多久。当我执行编译的文件时,它没有输出任何内容。因此,我使用GDB调试发生了什么。这是我发现的。
[New Thread 1932.0xec0]
[New Thread 1932.0x918]
[New Thread 1932.0x13dc]
[New Thread 1932.0x4f8]
[Thread 1932.0x918 exited with code 3221225781]
[Thread 1932.0x4f8 exited with code 3221225781]
During startup program exited with code 0xc0000135.
搜索后,我意识到原因是DLL文件缺乏。因此,我将Libssh.dll文件复制到了我的程序中的目录。然后,同样的问题。最后,我使用依赖关系Walker工具来找出所需的所有DLL文件。结果是libzlib.dll,libcrypto-1_1-x64.dll文件。我只将libzlib.dll文件添加到我的程序目录中。而且运行良好。我想我的程序没有在libcrypto中使用该功能。也许你也应该加上它们。