I have built a simple program in Visual Studio, as per the below.
#define LIBSSH_STATIC 1
#include <libssh/libssh.h>
#include <iostream>
#include <stdlib.h>
int main()
{
std::cout << "Hello World!\n";
ssh_session my_ssh_session;
int verbosity = SSH_LOG_PROTOCOL;
int port = 22;
my_ssh_session = ssh_new();
if (my_ssh_session == NULL)
exit(-1);
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "10.10.10.100");
ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
ssh_free(my_ssh_session);
}
For the Lisssh library, I have downloaded the code from here: https://github.com/ShiftMediaProject/libssh/releases
...and added the library to Visual Studio, following the instructions here How to manually add a library to a visual studio 2017 project?
The library works and the program compiles, my only issue is that in order for it to work I have to manually copy a file called ssh.dll into the folder where the program executes from.
I have tried in Visual Studio setting C/C , Code Generation -> Multi-threaded (/MT) to statically link the library, but the DLL is not getting included.
How can I create a single executable, that includes the ssh.dll?
Thanks
CodePudding user response:
A .dll
is a Dynamic Link Library; it's not meant to be included in an .exe
. There are ways, but they are ugly and difficult.
The "proper" and easier way is to build libssh as a static library instead; this will give you a .lib
file that you can add to your .exe
easily.
It looks like the downloads you used already contain these .lib
files. Just add the libssh.lib
file to your project, and omit the ssh.lib
(which is just an import library for the .dll
, as you can tell from the size of the file).