同一台服务器上,编译两个程序,都用到libpcap静态库,两个程序的makefile的格式差异很大,一个ok,一个链接出错。
-
> linking ...
-
g++ -o ./bin/biz -g -w -Wall -O2 -lpcap ../../Lib//Socket/bin/Socket.a
-
../../Lib//Socket/bin/Socket.a(PcapReader.o): In function `Socket::PcapReader::ReadEthernetPacket()':
-
PcapReader.cpp:(.text+0x3c): undefined reference to `pcap_next'
-
../../Lib//Socket/bin/Socket.a(PcapReader.o): In function `Socket::PcapReader::ReadIPPacket()':
-
PcapReader.cpp:(.text+0x6e): undefined reference to `pcap_next'
-
../../Lib//Socket/bin/Socket.a(PcapReader.o): In function `Socket::PcapReader::Close()':
-
PcapReader.cpp:(.text+0xa4): undefined reference to `pcap_close'
-
../../Lib//Socket/bin/Socket.a(PcapReader.o): In function `Socket::PcapReader::StartByDev(char const*, char const*)':
-
PcapReader.cpp:(.text+0x139): undefined reference to `pcap_open_live'
-
PcapReader.cpp:(.text+0x168): undefined reference to `pcap_compile'
-
PcapReader.cpp:(.text+0x17a): undefined reference to `pcap_setfilter'
-
PcapReader.cpp:(.text+0x19c): undefined reference to `pcap_close'
-
../../Lib//Socket/bin/Socket.a(PcapReader.o): In function `Socket::PcapReader::_FindDevByIP(char const*, char*, int)':
-
PcapReader.cpp:(.text+0x1f5): undefined reference to `pcap_findalldevs'
-
PcapReader.cpp:(.text+0x22c): undefined reference to `pcap_freealldevs'
-
collect2: ld 返回 1
-
make: *** [biz] 错误 1
但是包含的库什么的都类似啊,都用了-lpcap,找了半天,尝试了半天。
详细地对比,在一个makefile调整了一下-lpcap的位置:
LIBFILES += -lpthread
-lpcap\
${Lib_Base}/Socket/bin/Socket.a
把-lpcap换到Socket.a之后,编译ok。
貌似网上有说makefile的依赖关系是倒序的,有空研究一下。
阅读(4737) | 评论(0) | 转发(0) |