0

I am currently trying to create a c program that shall ssh into a couple of remote servers. I am attempting to link the libssh library to my program but I am having difficulty. This is my main source file:

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

int main(){\n
    printf("Attempting Library Call!\n");
    ssh_session my_ssh_session=ssh_new();
    printf("Exiting Program!\n");
    ssh_free(my_ssh_session);
    return (EXIT_SUCCESS);
}

Makefile:

all:
    gcc -Wall -g -I/home/user/SSH_CON/libssh/include -L/home/user/SSH_CON/libssh/lib main.c -o ssh -lssh

This is the first time I am attempting to link a library with a c program and I have having difficulty. The downloaded files that came with the library from https://www.libssh.org/ installer are as follows:

/libssh
    /bin
        libssh.dll
        libssh_threads.dll
    /CMake
        libssh-config.cmake
        libssh-config-version.cmake
    /include/libssh
        callbacks.h
        legacy.h
        libssh.h
        server.h
        sftp.h
        ssh2.h
    /lib
        /pkgconfig
            libssh.pc
            libssh_threads.pc
        libssh.dll.a
        libssh_threads.dll.a
    Uninstall.exe

I have done a lot of searching online, and have tried adding both the libssh.dll and the libssh.dll.a libraries. The gcc is successful in making the ssh.exe executable, but when I try to run it, I consistently receive this error:

/home/user/SSH_CON/ssh.exe: error while loading shared libraries: libssh.dll: cannot open shared object file: no such file or directory

I have no idea where to go from here. Does anyone have any suggestions?

UPDATE:

Placed the libssh.dll.a and libssh.dll into the working directory of my main.c file and now I am receiving this error:

/home/user/SSH_CON/ssh.exe: error while loading shared libraries: ?: cannot open shared object file: no such file or directory

Running ldd on my executable produced the following result:

ntdll.dll => /cygdrive/c/Windows/SYSTEM32/ntdll.dll
KERNEL32.DLL => /cygdrive/c/Windows/SYSTEM32/KERNEL32.DLL
KERNELBASE.dll => /cygdrive/c/Windows/SYSTEM32/KERNELBASE.dll
cygwin1.dll => /usr/bin/cygwin1.dll
libssh.dll => /home/user/SSH_CON/libssh.dll
ADVAPI32.DLL => /cygdrive/c/Windows/SYSTEM32/ADVAPI32.DLL
msvcrt.dll => /cygdrive/c/Windows/SYSTEM32/msvcrt.dll
SHELL32.DLL => /cygdrive/c/Windows/SYSTEM32/SHELL32.DLL
WS2_32.DLL => /cygdrive/c/Windows/SYSTEM32/WS2_32.DLL

Is there any way I can identify the missing library named ?? Is there any way I can compile this library to be static so that at runtime it does not depend on any shared libraries?

Community
  • 1
  • 1
  • check this. http://www.linfo.org/path_env_var.html – Andro May 28 '14 at 16:05
  • I would like the executable to be independent of shared library location/environmental variable configuration since I shall need to distribute this program once I finish. Is there any way to link a library (I think I need to include a static library?), compiling the program without the need to change the windows or UNIX PATH variables? – user3652784 May 28 '14 at 16:36
  • 1
    well you can always place the library in /usr/lib – Andro May 28 '14 at 16:48
  • Placing the libssh.dll file in the /usr/lib fixed part of the issue, but now i am getting that: /home/user/SSH_CON/ssh.exe: error while loading shared libraries: ?: cannot open shared object file: no such file or directory. Any idea what file it is trying to look for? – user3652784 May 28 '14 at 20:36

0 Answers0