Chinaunix首页 | 论坛 | 博客
  • 博客访问: 424997
  • 博文数量: 126
  • 博客积分: 35
  • 博客等级: 民兵
  • 技术积分: 1262
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-19 16:39
文章分类

全部博文(126)

文章存档

2017年(2)

2016年(20)

2015年(64)

2014年(24)

2013年(16)

我的朋友

分类: C/C++

2013-07-08 19:42:21

同一台服务器上,编译两个程序,都用到libpcap静态库,两个程序的makefile的格式差异很大,一个ok,一个链接出错。

  1. > linking ...
  2. g++ -o ./bin/biz -g -w -Wall -O2 -lpcap ../../Lib//Socket/bin/Socket.a
  3. ../../Lib//Socket/bin/Socket.a(PcapReader.o): In function `Socket::PcapReader::ReadEthernetPacket()':
  4. PcapReader.cpp:(.text+0x3c): undefined reference to `pcap_next'
  5. ../../Lib//Socket/bin/Socket.a(PcapReader.o): In function `Socket::PcapReader::ReadIPPacket()':
  6. PcapReader.cpp:(.text+0x6e): undefined reference to `pcap_next'
  7. ../../Lib//Socket/bin/Socket.a(PcapReader.o): In function `Socket::PcapReader::Close()':
  8. PcapReader.cpp:(.text+0xa4): undefined reference to `pcap_close'
  9. ../../Lib//Socket/bin/Socket.a(PcapReader.o): In function `Socket::PcapReader::StartByDev(char const*, char const*)':
  10. PcapReader.cpp:(.text+0x139): undefined reference to `pcap_open_live'
  11. PcapReader.cpp:(.text+0x168): undefined reference to `pcap_compile'
  12. PcapReader.cpp:(.text+0x17a): undefined reference to `pcap_setfilter'
  13. PcapReader.cpp:(.text+0x19c): undefined reference to `pcap_close'
  14. ../../Lib//Socket/bin/Socket.a(PcapReader.o): In function `Socket::PcapReader::_FindDevByIP(char const*, char*, int)':
  15. PcapReader.cpp:(.text+0x1f5): undefined reference to `pcap_findalldevs'
  16. PcapReader.cpp:(.text+0x22c): undefined reference to `pcap_freealldevs'
  17. collect2: ld 返回 1
  18. make: *** [biz] 错误 1
但是包含的库什么的都类似啊,都用了-lpcap,找了半天,尝试了半天。
详细地对比,在一个makefile调整了一下-lpcap的位置:
LIBFILES += -lpthread -lpcap\
            ${Lib_Base}/Socket/bin/Socket.a
把-lpcap换到Socket.a之后,编译ok。
貌似网上有说makefile的依赖关系是倒序的,有空研究一下。
阅读(4634) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~