我无法让Eclipse使用WinPCap构建项目。我通过项目设置对话框中的文件系统浏览器手动添加了路径wpcap.lib和Packet.lib。当我构建时,它说ld找不到库。我正在使用GNU Cygwin工具链。
来源:
#include "pcap.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
pcap_if_t *alldevs;
pcap_if_t *d;
int i=0;
char errbuf[PCAP_ERRBUF_SIZE];
/* Retrieve the device list from the local machine */
if (pcap_findalldevs(&alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);
exit(1);
}
return 0;
}
错误:
make all
Building file: ../src/main.cpp
Invoking: Cygwin C++ Compiler
g++ -I"C:\Users\parker\WpdPack\Include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP - MF"src/main.d" -MT"src/main.d" -o "src/main.o" "../src/main.cpp"
cygwin warning:
MS-DOS style path detected: C:\Users\parker\workspace\net\Debug
Preferred POSIX equivalent is: /cygdrive/c/Users/parker/workspace/net/Debug
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
../src/main.cpp: In function `int main(int, char**)':
../src/main.cpp:14: warning: unused variable 'd'
../src/main.cpp:15: warning: unused variable 'i'
Finished building: ../src/main.cpp
Building target: net.exe
Invoking: Cygwin C++ Linker
g++ -L"C:\Users\parker\WpdPack\Lib" -o "net.exe" ./src/main.o - lC:/Users/parker/WpdPack/Lib/wpcap.lib -lC:/Users/parker/WpdPack/Lib/Packet.lib
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lC:/Users/parker/WpdPack/Lib/wpcap.lib
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lC:/Users/parker/WpdPack/Lib/Packet.lib
collect2: ld returned 1 exit status
make: *** [net.exe] Error 1
makefile:45: recipe for target `net.exe' failed
库文件肯定位于指定的路径中。我觉得这些路径被/
改写而不是通常的Windows \
似乎很奇怪。我尝试使用/
和\
手动编辑路径,但它根本没有更改错误输出。