红联Linux门户
Linux帮助

求助,libnet函数库的应用问题?出现 undefined reference to `libnet_init'错误。

发布时间:2010-04-18 22:03:31来源:红联作者:静静飞舞
我在linux下已经安装了libnet函数库,可是在使用libnet_init()等函数的时候,用gcc编译总是显示 Undefined reference to "libnet_init" 的字样,在代码中我已经写了 #include , 而且/usr/include 里也有libnet.h,/usr/include/libnet 下也有函数声明文件libnet-functions.h。
可是在编译libnet的sample中的c文件显示错误,如下
[root@bogon sample]# gcc tftp.c
/tmp/ccoxChZD.o: In function `main':
tftp.c:(.text+0x89): undefined reference to `libnet_init'
tftp.c:(.text+0x11a): undefined reference to `libnet_name2addr4'
tftp.c:(.text+0x167): undefined reference to `libnet_name2addr4'
tftp.c:(.text+0x3a7): undefined reference to `libnet_build_udp'
tftp.c:(.text+0x3bb): undefined reference to `libnet_geterror'
tftp.c:(.text+0x448): undefined reference to `libnet_build_ipv4'
tftp.c:(.text+0x45c): undefined reference to `libnet_geterror'
tftp.c:(.text+0x483): undefined reference to `libnet_write'
tftp.c:(.text+0x497): undefined reference to `libnet_geterror'
tftp.c:(.text+0x4db): undefined reference to `libnet_destroy'
tftp.c:(.text+0x4fd): undefined reference to `libnet_destroy'
collect2: ld 返回 1
[root@bogon sample]#
文章评论

共有 3 条评论

  1. 于 2012-10-27 13:13:46发表:

    你顶层Makefile文件中这行连接库的#LIBS += net/libnet.a被注释了吧,除掉前面的#就可以了。

  2. 静静飞舞 于 2010-04-19 14:28:21发表:

    谢谢楼上的 我在gcc的时候加上了-lnet 但是还是不可以,还是会出现上面的错误。。。。。。。。。

  3. hantu 于 2010-04-18 22:33:43发表:

    看libnet软件包的说明,看看是否要在gcc后加-l参数以链接函数库,并确认的#include语句写正确了没有.