我遇到了一个问题,我无法编译使用 libsshssh client . 这取自 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):未定义引用to_imp__ssh_userauth_password'C:\ Users \ AppData \ Local \ Temp \ ccI0eQk0.o:ssh.c :( . text 0xca):未定义引用_imp__ssh_disconnect'C:\ Users \ AppDat a \ Local \ Temp \ ccI0eQk0.o:ssh.c :( . text 0xd8):undefined reference to_imp__ssh_free'colle2.exe:error:ld返回1退出状态