在linux上编译外部库的问题

时间:2010-06-10 11:39:37

标签: c++ linux libssh

所以我试图在linux上编译libssh2库,但是当我尝试编译时 例如,它出现了很多错误,即使我包含它要求的头文件,它仍然要求它。 以下是错误消息和生成的消息:

~/ gcc -include /home/Roosevelt/libssh2-1.2.5/src/libssh2_config.h -o lolbaise /home/Roosevelt/libssh2-1.2.5/example/scp.c
/home/Roosevelt/libssh2-1.2.5/example/scp.c:7:28: error: libssh2_config.h: No such file or directory
/home/Roosevelt/libssh2-1.2.5/example/scp.c: In function 'main':
/home/Roosevelt/libssh2-1.2.5/example/scp.c:39: error: storage size of 'sin' isn't known
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: 'AF_INET' undeclared (first use in this function)
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: (Each undeclared identifier is reported only once
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: for each function it appears in.)
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: 'SOCK_STREAM' undeclared (first use in this function)
/home/Roosevelt/libssh2-1.2.5/example/scp.c:87: error: invalid application of 'sizeof' to incomplete type 'struct sockaddr_in'

以下是新错误:

scp.c:(.text+0x106): undefined reference to `libssh2_init'
scp.c:(.text+0x1fe): undefined reference to `libssh2_session_init_ex'
scp.c:(.text+0x234): undefined reference to `libssh2_session_startup'
scp.c:(.text+0x288): undefined reference to `libssh2_hostkey_hash'
scp.c:(.text+0x36f): undefined reference to `libssh2_userauth_password_ex'
scp.c:(.text+0x3e7): undefined reference to `libssh2_userauth_publickey_fromfile_ex'
scp.c:(.text+0x437): undefined reference to `libssh2_scp_recv'
scp.c:(.text+0x531): undefined reference to `libssh2_channel_read_ex'
scp.c:(.text+0x5f8): undefined reference to `libssh2_channel_free'
scp.c:(.text+0x628): undefined reference to `libssh2_session_disconnect_ex'
scp.c:(.text+0x636): undefined reference to `libssh2_session_free'
scp.c:(.text+0x66e): undefined reference to `libssh2_exit'
collect2: ld returned 1 exit status

3 个答案:

答案 0 :(得分:2)

不包含头文件:libssh2_config.h

源代码中有一个包含指令,因此您必须使用-I选项指明标题的路径:gcc -I/home/Roosevelt/libssh2-1.2.5/src

-include选项必须用于包含头文件,该头文件未明确包含在具有#include指令的源代码中。

答案 1 :(得分:0)

我刚刚克隆了当前的git版本并进入1.2.5版本,但我无法重现您的问题。

./buildconf
./configure
make

工作正常。你准备做什么?

答案 2 :(得分:0)

我建议你阅读这篇文章我遇到了同样的问题,但在阅读本文后我得到了修复,希望对你有所帮助,http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html