我可以通过将 SDK 文件夹从C:\WdpPack
我的C:\User
文件夹中移动来编译它。我对 Windows 不太熟悉,所以我不确定为什么会这样,也许与权限有关?
更新:
运行后perl Makefile.PL
,运行gmake
编译模块失败并出现错误:
[...]
stubs.inc:91:8: error: redefinition of 'struct pcap_if'
[...]
stubs.inc:267:5: error: conflicting types for 'pcap_compile_nopcap'
[...]
stubs.inc:357:8: error: redefinition of 'struct pcap_rmtauth'
[...]
stubs.inc:363:10: error: conflicting types for 'pcap_open'
[...]
stubs.inc:438:8: error: redefinition of 'struct pcap_send_queue'
[...]
stubs.inc:497:8: error: redefinition of 'struct pcap_samp'
要解决此问题,请编辑文件stubs.inc
:
删除第 91-97 行
struct pcap_if {
struct pcap_if *next;
char *name; /* name to hand to "pcap_open_live()" */
char *description; /* textual description of interface, or NULL */
struct pcap_addr *addresses;
bpf_u_int32 flags; /* PCAP_IF_ interface flags */
};
删除行:267-271
int pcap_compile_nopcap(int snaplen, int linktype, struct bpf_program *fp, char *str, int optimize, bpf_u_int32 netmask);
int pcap_compile_nopcap(int snaplen, int linktype, struct bpf_program *fp, char *str, int optimize, bpf_u_int32 netmask) {
FUNCTION_NOT_IMPLEMENTED_ERROR(pcap_compile_nopcap)
return -1;
删除行:357-361
struct pcap_rmtauth {
int type;
char *username;
char *password;
};
删除第 438-442 行:
struct pcap_send_queue{
u_int maxlen;
u_int len;
char *buffer;
};
删除第 519-521 行:
struct pcap_samp {
int method;
int value;
};
现在gmake
编译文件,但链接器失败:
[...]
C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Pcap.o:Pcap.c:(.text+0x23be): undefined reference to `pcap_geterr'
C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Pcap.o:Pcap.c:(.text+0x2580): undefined reference to `pcap_geterr'
C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Pcap.o:Pcap.c:(.text+0x2590): undefined reference to `pcap_stats'
C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Pcap.o:Pcap.c:(.text+0x2820): undefined reference to `pcap_fileno'
C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Pcap.o:Pcap.c:(.text+0x29c4): undefined reference to `pcap_file'
[...]
这里的问题是我们与 32 位库链接wpcap.lib
,请参阅这篇文章。事实证明,文件夹中的 SDK 中有一个 64 位版本的库Lib/x64
。所以我们必须Makefile.PL
用正确的库路径重新运行:
perl Makefile.PL INC=-IC:/Users/Me/Libraries/npcap/Include "LIBS=-LC:/Users/Me/Libraries/npcap/Lib/x64 -lwpcap"
(更改上述命令中的路径以符合您的 SDK 安装目录)然后重新运行gmake
.