编译独立的exe& libssh

时间:2018-02-16 13:09:30

标签: c cross-compiling libssh

我一直在努力使用libssh使用i686-w64-mingw32-gcc编译独立的exe;

#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);

我使用以下命令编译此代码:

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

我在:

中提取了libssh-0.7.2-mingw.zip
/tmp/lib/libssh-0.7.2/lib

如果没有libssh.lib,libssh-0.7.2-msvc.zip就完全无法编译

-L/tmp/libssh-0.7.2/bin

代码编译但是当用wine运行时,它仍然会查找ssh.dll:

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

环境:

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)

我在这里缺少什么?我甚至用正确的方式使用两个不同的libssh包吗?我尝试了#define LIBSSH_STATIC 1和#define LIBSSH_STATIC但这些似乎没有任何区别,我似乎无法找到手动告诉编译器在任何开关中包含ssh.dll的方法。

0 个答案:

没有答案