0

I've been struggling to compile stand-alone exe with i686-w64-mingw32-gcc using libssh;

#define LIBSSH_STATIC 1
#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>

int main() {
    ssh_session my_ssh_session;
    int rc;
    char *password;
    int port = 22;
    my_ssh_session = ssh_new();
    if (my_ssh_session == NULL)
        exit(-1);
    ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "myhost.com");
    ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
    ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, "user");
    rc = ssh_connect(my_ssh_session);
    password = ("mypassword");
    rc = ssh_userauth_password(my_ssh_session, NULL, password);
    ssh_disconnect(my_ssh_session);
    ssh_free(my_ssh_session);

I compile this code with following command:

i686-w64-mingw32-gcc ssh_client2.c -o client_v2.exe -I/tmp/lib/libssh-0.7.2/include/ -lssh -L/tmp/lib/libssh-0.7.2/lib -L/tmp/libssh-0.7.2/lib -static

I have libssh-0.7.2-mingw.zip extracted in:

/tmp/lib/libssh-0.7.2/lib

And libssh-0.7.2-msvc.zip in - couldn't compile at all without libssh.lib

-L/tmp/libssh-0.7.2/bin

The code compiles but when running with wine, it still looks for ssh.dll:

err:module:import_dll Library ssh.dll (which is needed by L"Z:\\location\\of\\exe\\client_v2.exe") not found

Environment:

i686-w64-mingw32-gcc (GCC) 6.3.0 20170516
Linux l6453p 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u5 (2017-09-19) x86_64 GNU/Linux
wine-1.8.7 (Debian 1.8.7-2)

What am i missing here? Am i even doing this in the proper way with using two different libssh-packages? I tried both #define LIBSSH_STATIC 1 and #define LIBSSH_STATIC but these don't seem to make any difference and i can't seem to find way to manually tell the compiler to include ssh.dll with any switch.

Olli
  • 65
  • 2
  • 8
  • _The code compiles but when running with wine, it still looks for ssh.dll:_ Have you tried placing a copy of ssh.dll in the executable directory? Also, in case it would be useful, here is a wiki page - _[HOWTO Specify the Location of Libraries for use with MinGW](http://www.mingw.org/wiki/HOWTO_Specify_the_Location_of_Libraries_for_use_with_MinGW)_ – ryyker Feb 16 '18 at 13:36
  • Hi, yes, And like that the executable works, but since this is related to pentesting work, i'd need the whole functionality in single file - but thanks anyway – Olli Feb 17 '18 at 15:27
  • Did you find an answer? – 0xT0mT0m Sep 23 '18 at 12:24
  • No, unfortunatlely i did not - had to switch to pyrhon – Olli Sep 23 '18 at 12:26

0 Answers0