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