欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【使用 libssh】编译失败, undefined reference to ‘ssh_new‘, undefined reference to ‘ssh_free‘

程序员文章站 2022-07-08 14:23:41
...

来到 libssh 官网, 跟随着 tutorial 熟悉使用 libssh。

然而一开始我就遇到了困难。 chapter 1 中的第一段代码, 我总是没有办法编译通过。

文件名 main.c

#include <libssh/libssh.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
	ssh_session my_ssh_session = ssh_new();
	if (my_ssh_session == NULL)
		exit(-1);
	ssh_free(my_ssh_session);
}

【使用 libssh】编译失败, undefined reference to ‘ssh_new‘, undefined reference to ‘ssh_free‘

最终我找到了一篇关于使用 libssh 的博客: 使用 libssh 编写 client
原来是我在用 gcc 命令编译的时候没有使用适当的参数:

gcc main.c -o main  # 编译失败

gcc main.c -o main -Wall -lssh  # 编译成功
  • -Wall 生成所有警告信息
  • -lssh 暂时不明所用

在此感谢 使用 libssh 编写 client 博客的作者

上一篇: 单表查询

下一篇: mysql 单表查询