在Windows 64位上编译gopacket [英] compile gopacket on windows 64bit

查看:114
本文介绍了在Windows 64位上编译gopacket的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在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:

  1. 安装go_amd64(将go二进制文件添加到您的PATH中)
  2. 安装TDM GCC x64(将TDM-GCC二进制文件添加到PATH)
  3. 还将TDM-GCC \ x86_64-w64-mingw32 \ bin添加到您的PATH
  4. 安装 Winpcap
  5. 下载Winpcap开发人员包并将其解压缩到C:\
  1. Install go_amd64 (add go binaries to your PATH)
  2. Install TDM GCC x64 (add TDM-GCC binaries to your PATH)
  3. Also add TDM-GCC\x86_64-w64-mingw32\bin to your PATH
  4. Install Winpcap
  5. 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:

  1. 在您的PC中找到wpcap.dll和packet.dll(通常在c:\ windows \ system32
  2. 中)
  3. 将它们复制到其他临时文件夹中,否则您将必须为以下命令提供管理员权限
  4. 在那些文件 gendef wpcap.dll gendef packet.dll 上运行gendef(可通过MinGW Installation Manager获得,软件包mingw32-gendef)
  5. 这将生成.def文件
  6. 现在,我们将生成静态库文件:
  7. 运行 dlltool --as-flags =-64 -m i386:x86-64 -k --output-lib libwpcap.a --input-def wpcap.def
  8. dlltool --as-flags =-64 -m i386:x86-64 -k --output-lib libpacket.a --input-def packet.def
  9. 现在只需将libwpcap.a和libpacket.a复制到c:\ WpdPack \ Lib \ x64
  1. find wpcap.dll and packet.dll in your PC (typically in c:\windows\system32
  2. copy them to some other temp folder or else you'll have to supply Admin privs to the following commands
  3. run gendef on those files gendef wpcap.dll and gendef packet.dll (obtainable with MinGW Installation Manager, package mingw32-gendef)
  4. this will generate .def files
  5. Now we'll generate the static libraries files:
  6. run dlltool --as-flags=--64 -m i386:x86-64 -k --output-lib libwpcap.a --input-def wpcap.def
  7. and dlltool --as-flags=--64 -m i386:x86-64 -k --output-lib libpacket.a --input-def packet.def
  8. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆