我目前正在尝试创建一个可以ssh到几个远程服务器的c程序。我试图将libssh库链接到我的程序,但我遇到了困难。这是我的主要源文件:
#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);
}
生成文件:
all:
gcc -Wall -g -I/home/user/SSH_CON/libssh/include -L/home/user/SSH_CON/libssh/lib main.c -o ssh -lssh
这是我第一次尝试将库与c程序链接而且我遇到了困难。从https://www.libssh.org/安装程序随库提供的下载文件如下:
/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
我在线搜索了很多,并尝试添加libssh.dll和libssh.dll.a库。 gcc成功地使ssh.exe可执行,但当我尝试运行它时,我一直收到此错误:
/home/user/SSH_CON/ssh.exe: error while loading shared libraries: libssh.dll: cannot open shared object file: no such file or directory
我不知道从哪里开始。有没有人有任何建议?
将libssh.dll.a和libssh.dll放入main.c文件的工作目录中,现在我收到此错误:
/home/user/SSH_CON/ssh.exe: error while loading shared libraries: ?: cannot open shared object file: no such file or directory
在我的可执行文件上运行ldd会产生以下结果:
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
有什么方法可以识别名为?
的缺失库吗?有没有什么办法可以将这个库编译成静态的,这样在运行时它就不依赖于任何共享库了?