我试图将我的程序与 libssh 静态库链接。
以下是我从 libssh 教程复制的简单代码:
//sshtest.c
#define LIBSSH_STATIC 1
#include <libssh/libssh.h>
#include <stdlib.h>
int main()
{
ssh_session my_ssh_session;
my_ssh_session = ssh_new();
if (my_ssh_session == NULL)
exit(-1);
ssh_free(my_ssh_session);
}
Run Code Online (Sandbox Code Playgroud)
我将库文件放入libssh.a子目录中libs/
然后用命令编译gcc sshtest.c -Llibs -lssh -o sshtest
输出是一堆未定义的引用错误,例如:
libs/libssh.a(wrapper.c.o): In function `crypto_free':
/home/gg/libssh/src/wrapper.c:156: undefined reference to `BN_clear_free'
/home/gg/libssh/src/wrapper.c:157: undefined reference to `BN_clear_free'
libs/libssh.a(libcrypto.c.o): In function `ssh_reseed':
/home/gg/libssh/src/libcrypto.c:77: undefined reference to `RAND_add'
libs/libssh.a(libcrypto.c.o): In function `sha1_init':
/home/gg/libssh/src/libcrypto.c:84: undefined reference to `EVP_MD_CTX_new'
Run Code Online (Sandbox Code Playgroud)
可以通过将动态库文件(libssh.so, libssh.so.4, libssh.so.4.5.0)复制到该libs/文件夹中来解决该问题,但我猜在这种情况下编译器将链接动态库。 …