我在我的 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/