找不到 libssh 符号错误 gcc

libssh symbols not found error gcc

我正在尝试根据 Wil Allsopp 的笔测试书构建一个简单的 SSH 客户端。在 Mac OS High Sierra 上工作,gcc-4.2 和使用 Homebrew 安装的 libssh。最简单的代码版本是:

#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{    
    ssh_session my_ssh_session;
    my_ssh_session = ssh_new();
    ssh_free(my_ssh_session);
    return 0;
}

然而,简单的 gcc 构建 (gcc -Wall ssh_client.c) 会产生以下错误:

Undefined symbols for architecture x86_64:

"_ssh_free", referenced from: _main in ssh_client-aa8f09.o

"_ssh_new", referenced from: _main in ssh_client-aa8f09.o

ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1

谁能解释这些错误以及我该如何修复它们?

您的构建行似乎不包含任何包含和 linker 标志。我想它正在获取 headers 而不是 ssh 到 link 的库。查看 pkgconfig 以获取维护它的简单方法。