首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在Raspbian中使用libssh编译代码,尽管这里和其他地方都有说明

问无法在Raspbian中使用libssh编译代码,尽管这里和其他地方都有说明
EN

Stack Overflow用户
提问于 2018-06-07 22:18:09
回答 1查看 231关注 0票数 1

我希望在我把剩下的头发拔出来之前,有人能给我一些想法。我正在使用Raspberry Pi 3和libssh-dev,在编译代码时遇到了问题。有什么想法吗?

我在Raspbian中的默认存储库中安装了libssh-dev,并花了一整天的时间来获取编译时包含的库。下面是我的测试代码,在编译时适当地设置了用户和主机。

代码语言:javascript
复制
#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;
}

我使用下面的命令来编译代码。

代码语言:javascript
复制
gcc -DLIBSSH_STATIC test.c -o test

这是我收到的错误信息。我的假设是图书馆没有正确地包括在内?

代码语言:javascript
复制
/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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-08 08:14:32

你说得对,图书馆没有被正确地包括在内。

#include <libssh/libssh.h>只告诉编译器libssh提供了哪些函数以及如何调用它们,但是您还需要告诉链接器在哪里找到二进制库。

要链接到静态libssh二进制文件,可以将路径添加到编译器命令行的静态存档(可能是/usr/lib/arm-linux-gnueabihf/libssh.a)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50750887

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档