我希望在我把剩下的头发拔出来之前,有人能给我一些想法。我正在使用Raspberry Pi 3和libssh-dev,在编译代码时遇到了问题。有什么想法吗?
我在Raspbian中的默认存储库中安装了libssh-dev,并花了一整天的时间来获取编译时包含的库。下面是我的测试代码,在编译时适当地设置了用户和主机。
#define LIBSSH_STATIC 1
#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
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, "localhost");
ssh_options_set (my_ssh_session, SSH_OPTIONS_USER, "username");
ssh_options_set (my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
ssh_options_set (my_ssh_session, SSH_OPTIONS_PORT, &port);
// other code here
ssh_free(my_ssh_session);
return 0;
}我使用下面的命令来编译代码。
gcc -DLIBSSH_STATIC test.c -o test这是我收到的错误信息。我的假设是图书馆没有正确地包括在内?
/tmp/ccVIYUs5.o: In function `main':
printschedules.c:(.text+0x1c): undefined reference to `ssh_new'
printschedules.c:(.text+0x44): undefined reference to `ssh_options_set'
printschedules.c:(.text+0x54): undefined reference to `ssh_options_set'
printschedules.c:(.text+0x68): undefined reference to `ssh_options_set'
printschedules.c:(.text+0x7c): undefined reference to `ssh_options_set'
printschedules.c:(.text+0x84): undefined reference to `ssh_free'
collect2: error: ld returned 1 exit status发布于 2018-06-08 08:14:32
你说得对,图书馆没有被正确地包括在内。
#include <libssh/libssh.h>只告诉编译器libssh提供了哪些函数以及如何调用它们,但是您还需要告诉链接器在哪里找到二进制库。
要链接到静态libssh二进制文件,可以将路径添加到编译器命令行的静态存档(可能是/usr/lib/arm-linux-gnueabihf/libssh.a)。
https://stackoverflow.com/questions/50750887
复制相似问题