c - 从 libssh2 获取 undefined reference

标签 c ubuntu ssh libssh2

我在我的 Ubuntu Linux 上安装了 libssh2 库。编译 C 代码时,我收到此消息:

对 `libssh2_session_init_ex' 的 undefined reference

我从他们的网站下载了 libssh2。我按照如何在我的计算机上安装它的说明进行操作,但似乎我仍然缺少一些东西。

这是我的 make 文件中的代码:

all: ssh
     ssh: mysshpass.c
     gcc -lssh2 -g -o mysshpass mysshpass.c

clean:
     rm -rf mysshpass

C代码的include部分:

1 #include <stdlib.h>
2 #include <libssh2.h>
3 #include <libssh2_sftp.h>
4 
5 #include <sys/socket.h>
6 #include <netinet/in.h>
7 #include <arpa/inet.h>
8 #include <sys/types.h>
9 #include <stdio.h>
10 #include <string.h>
11 
12 //#include <libssh2_config.h>
13 
14 int main(int argc, char *argv[])

非常感谢

注意:

我使用了这条新线:

all: ssh

ssh: mysshpass.c
    gcc -g -Lusr/src/libssh2-1.4.1/include -o mysshpass mysshpass.c
clean:
    rm -rf mysshpass

但仍然存在相同的编译错误。顺便说一句,有人告诉我还要安装 libssh2-devel,但我不知道该怎么做。

谢谢

最佳答案

1) 卸载你得到的东西。有什么地方不对劲,它的存在只会让事情变得困惑。摆脱它。

2) *像这样安装"libssh2-dev:

sudo apt-get install libssh2-dev libssh2

3) 再次尝试构建您的应用程序。

确保您的 makefile 或构建脚本指向正确的位置(“-I”用于编译时 header ,“-L”用于链接时库)

祝你好运!

关于c - 从 libssh2 获取 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10265431/

相关文章:

python - 从 Linux Azure VM 运行 Node 或 Python 应用程序

c - 在 C 中使用第三方 ADT(GLib、sys/queue.h 等)

c++ - 内存浪费?如果 main() 应该只返回 0 或 1,为什么 main 声明为 int 而不是 short int 甚至 char?

linux - openssl 验证和 s_client 命令之间的差异

Android Studio - Ubuntu 上的空白菜单项

regex - 通过ssh运行的perl正则表达式命令行

C代码在Tiny C Compiler下编译并运行,但在GCC下无法运行

c - 编译器 C 的全局变量、静态变量和字符串文字的位置地址在哪里?

linux - 无法在 Ubuntu 中使用 Cabal

bash - 使用 cURL 在 BASH 脚本中发送 JSON