----- Original Message -----
> From: "petergeorgenm" <[email protected]>
> To: [email protected]
> Sent: Monday, February 1, 2021 2:04:18 PM
> Subject: Function behaves differently when libssh is compiled statically
> 
> I wrote a simple connection setup following the tutorial:
> //main.c
> #pragma comment(lib, "user32")
> #pragma comment(lib, "Advapi32")
> #pragma comment(lib, "Shell32")
> #pragma comment(lib, "Ws2_32")
> 
> #include <stdio.h>
> #include <libssh/sftp.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> 
> int main(void){
> int ret_c=0;
> int rc;
> int port=22;
> ssh_session the_session=ssh_new();
> if(the_session==NULL) {printf("1\n"); return -1;}
> 
> ssh_options_set(the_session, SSH_OPTIONS_HOST, "[email protected]");
> ssh_options_set(the_session, SSH_OPTIONS_PORT, &port);
> 
> rc=ssh_connect(the_session);
> if(rc !=SSH_OK) {
> ssh_free(the_session);
> printf("2, %d\n", rc);
> getchar();
> } else {
> printf("success\n");
> getchar();
> }
> 
> ssh_disconnect(the_session);
> ssh_free(the_session);
> return 0;
> }
> 
> I used vcpkg to install both static and dynamic versions of libssh, they
> reside as follows respectively:
> C:\Users\User\vcpkg\installed\x86-windows-static\
> C:\Users\User\vcpkg\installed\x86-windows\
> If I compile the previous code dynamically with:
> cl /I C:\Users\User\vcpkg\installed\x86-windows\include main.c /link
> C:\Users\User\vcpkg\installed\x86-windows\lib\* /SUBSYSTEM:CONSOLE
> and then run, the output I see is:
> success
> 
> If I compile it statically with:
> cl /D LIBSSH_STATIC /I
> C:\Users\User\vcpkg\installed\x86-windows-static\include main.c /link
> C:\Users\User\vcpkg\installed\x86-windows-static\lib\* /SUBSYSTEM:CONSOLE
> and then run, the output I see is:
> 2, -1
> 
> Both versions compile and link without any errors. I also tried to use putty
> to ssh to [email protected] and it works fine.
> Please tell me if I need to provide any more debugging information, or if any
> information isn't clear.

Hello,

Could you please try to call ssh_init() before calling any other function from 
libssh (and ssh_finalize() at the end)?
When using dynamic linking this will be a no-op.

This is a requirement when statically linked. It is mentioned in Chapter 8 of 
the tutorial and in the API documentation. I'm sorry that this is not better 
documented.

Best regards,
Anderson


Reply via email to