0
votes

I am running into an issue where I am not able to compile an ssh client which is using libssh. This is taken from 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);
    }

I have tried this command and does not help:

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

and I am getting this error:

c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lssh collect2.exe: error: ld returned 1 exit status

any ideas? thanks!


I guess the library is found with the following command, however I get this error:

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: In function 'main': ssh.c:35:52: warning: passing argument 3 of 'ssh_options_set' makes pointer from integer without a cast [-Wint-conversion] ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, 443); ^~~ In file included from ssh.c:19:0: c:\mingw\lib\gcc\mingw32\6.3.0\include\libssh\libssh.h:495:16: note: expected 'const void *' but argument is of type '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): undefined reference to _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): undefined reference to _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): undefined reference to _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): undefined reference to _imp__ssh_disconnect' C:\Users\AppData\Local\Temp\ccI0eQk0.o:ssh.c:(.text+0xd8): undefined reference to_imp__ssh_free' collect2.exe: error: ld returned 1 exit status

1
-L C:\MinGW\lib\gcc\mingw32\6.3.0\include\libssh should be: -L C:\MinGW\lib\gcc\mingw32\6.3.0\lib\libsshWilly K.
Did you manage to find an answer?Tom Wolters

1 Answers

0
votes

You should keep a clear mind. After u have compiled the libssh, you got three directories here. lib, include, and bin. Use gcc with the option : -Iinclude -Llib -lssh . This tell the compiler the include directory and lib directory for your program. And the last option is to tell the compiler which .a file you use. This should compiled with success. However, you never know how long this road u should go. When I execute the file I compiled, it didn't output anything. So, I use gdb to debug what happened. Here is what I found.

[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.

After searching, I realized the reason is that dll files lack. So, I copyed the libssh.dll file to the directory with my program. Then, same issue. Finally, I use the dependency walker tool to find out all the dll files I need. The result is, libzlib.dll, libcrypto-1_1-X64.dll file. I just add libzlib.dll file to my program directory. And it runs fine. I guess my program didn't use the function in libcrypto. Maybe u should add them too.