在windows 10上使用草莓perl安装Net::Pcap

在windows 10上使用草莓perl安装Net::Pcap,perl,libpcap,winpcap,strawberry-perl,npcap,Perl,Libpcap,Winpcap,Strawberry Perl,Npcap,我正在尝试使用portable草莓Perl v5.28.1版安装Net::Pcap(),以下是我的步骤: 1.我从安装了npcap(windows 10的winpcap) 2.我从下载了npcap sdk 3.我将SDK zip文件夹解压缩到c:/WdpPack,并验证Include和Lib文件夹是否包含头文件和库 4.然后运行以下命令 perl Makefile.PL INC=-IC:/WpdPack/Include "LIBS=-LC:/WpdPack/Lib -lwpcap" 我收到以下

我正在尝试使用portable草莓Perl v5.28.1版安装Net::Pcap(),以下是我的步骤:

1.我从安装了npcap(windows 10的winpcap)

2.我从下载了npcap sdk

3.我将SDK zip文件夹解压缩到c:/WdpPack,并验证Include和Lib文件夹是否包含头文件和库

4.然后运行以下命令

perl Makefile.PL INC=-IC:/WpdPack/Include "LIBS=-LC:/WpdPack/Lib -lwpcap"
我收到以下错误消息:

socket.h patched... ok
looking for -lwpcap... yes
checking for pcap_lib_version() in -lwpcap... no
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
You appear to lack the WinPcap developer pack.

If it is installed in a non-standard location, please try setting the LIBS
and INC values on the command line.  For instance, if you have unzipped the
developer's pack in C:\WpdPack, you should execute:

    perl Makefile.PL INC=-IC:/WpdPack/Include "LIBS=-LC:/WpdPack/Lib -lwpcap"

Or get and install the WinPcap developer's pack from
  http://www.winpcap.org/install/
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

你知道如何解决这个问题吗?

我可以通过将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中的文件夹
Lib/x64
中有一个64位版本的库。因此,我们必须使用正确的库路径重新运行
Makefile.PL

perl Makefile.PL INC=-IC:/Users/Me/Libraries/npcap/Include "LIBS=-LC:/Users/Me/Libraries/npcap/Lib/x64 -lwpcap"

(更改上述命令中的路径以符合SDK的安装目录),然后重新运行
gmake

我在
Makefile.PL
中启用了
$DEBUG
标志,从输出中,编译器似乎找不到头
pcap.h
。这很奇怪,因为编译器被赋予了
-IC:/WpdPack/Include
标志谢谢,现在当我运行perl Makefile时,它成功地完成了,但是当我运行gmake时,我得到了以下错误:PCAP_API char*PCAP_lookupdev(char*)^~~~~~~~~~~~~~~~~Pcap.c:在函数“XS_Net__Pcap_strerror”中:Pcap.c:1703:9:警告:赋值从指针目标类型[-Wdiscarded限定符]RETVAL=Pcap_strerror(错误);^Pcap.xs:在函数“xs_Net_Pcap_getevent”中:Pcap.xs:1038:13:警告:从指针强制转换为不同大小的整数[-Wpointer to int cast]h=(无符号int)Pcap_getevent(p)^是的,我在运行
gmake
时也会出错,也许你应该在GitHub将其报告为一个bug?另请参阅之前的一次尝试(这似乎与
dmake
)另一个想法是尝试使用
cygwin
进行安装?谢谢,我能够根据你的答案编译它,现在让我们看看它在windows 10下是如何工作的:)