在Windows 64位上编译gopacket [英] compile gopacket on windows 64bit
问题描述
我试图在Windows 10上使用 gopacket .
我正在使用它来嗅探数据包并将其直接注入NIC或从NIC注入数据.
我可以轻松地使用GOARCH = 386编译和运行我的代码,但不能在GOARCH = amd64中运行.
I am trying to use gopacket on my windows 10.
I'm using it to sniff and inject packets directly to/from the NIC.
I can easily compile and run my code with GOARCH=386 but can't in GOARCH=amd64.
值得一提的是:我不打算交叉编译.
我正在使用go1.6.windows-386来编译32位版本,当我尝试使用GOARCH = amd64进行编译时,我使用了go1.6.windows-amd64.
Worth noticing: I am NOT trying to cross-compile.
I'm using go1.6.windows-386 to compile the 32bit version and when I try to compile with GOARCH=amd64 I use go1.6.windows-amd64.
我将TDM-GCC用作linux之类的编译工具.
该错误不是指示性的.它只是说
I used TDM-GCC as linux like compile tools.
The error isn't indicative. it just says
c:/WpdPack/Lib/x64/wpcap.lib:添加符号时出错:格式错误的文件collect2.exe:错误ld返回1退出状态
即使有可能,没有人设法构建它吗?
Did anyone manage to build this, if it's even possible?
推荐答案
好的,所以我知道了.
为了在Windows上编译gopacket 64bit,您需要执行以下操作:
OK so I have figured it out.
In order to compile gopacket 64bit on windows you need to do the following:
- 安装go_amd64(将go二进制文件添加到您的PATH中)
- 安装TDM GCC x64(将TDM-GCC二进制文件添加到PATH)
- 还将TDM-GCC \ x86_64-w64-mingw32 \ bin添加到您的PATH
- 安装 Winpcap
- 下载Winpcap开发人员包并将其解压缩到C:\
- Install go_amd64 (add go binaries to your PATH)
- Install TDM GCC x64 (add TDM-GCC binaries to your PATH)
- Also add TDM-GCC\x86_64-w64-mingw32\bin to your PATH
- Install Winpcap
- Download Winpcap developer's pack and extract it to C:\
现在的要点是缺少linux静态库文件
(libwpcap.a和libpacket.a)来自lib/x64文件夹.我不知道为什么他们不是
包含在开发人员包中,但无论如何,这就是我们生成它们的方式:
Now the point is that there are missing linux static libraries files
(libwpcap.a and libpacket.a) from lib/x64 folder. I don't know why they weren't
included in the developers pack but anyway that's how we can generate them:
- 在您的PC中找到wpcap.dll和packet.dll(通常在c:\ windows \ system32 中)
- 将它们复制到其他临时文件夹中,否则您将必须为以下命令提供管理员权限
- 在那些文件
gendef wpcap.dll
和gendef packet.dll
上运行gendef(可通过MinGW Installation Manager获得,软件包mingw32-gendef) - 这将生成.def文件
- 现在,我们将生成静态库文件:
- 运行
dlltool --as-flags =-64 -m i386:x86-64 -k --output-lib libwpcap.a --input-def wpcap.def
- 和
dlltool --as-flags =-64 -m i386:x86-64 -k --output-lib libpacket.a --input-def packet.def
- 现在只需将libwpcap.a和libpacket.a复制到c:\ WpdPack \ Lib \ x64
- find wpcap.dll and packet.dll in your PC (typically in c:\windows\system32
- copy them to some other temp folder or else you'll have to supply Admin privs to the following commands
- run gendef on those files
gendef wpcap.dll
andgendef packet.dll
(obtainable with MinGW Installation Manager, package mingw32-gendef) - this will generate .def files
- Now we'll generate the static libraries files:
- run
dlltool --as-flags=--64 -m i386:x86-64 -k --output-lib libwpcap.a --input-def wpcap.def
- and
dlltool --as-flags=--64 -m i386:x86-64 -k --output-lib libpacket.a --input-def packet.def
- Now just copy both libwpcap.a and libpacket.a to c:\WpdPack\Lib\x64
就是这样.
现在gopacket应该可以编译了.
That's it.
Now gopacket should compile with no problems.
这篇关于在Windows 64位上编译gopacket的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!