compile gopacket on windows 64bit

你。 提交于 2019-12-03 14:57:22
J. Dow

OK so I have figured it out.
In order to compile gopacket 64bit on windows you need to do the following:

  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:\

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. 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

That's it.
Now gopacket should compile with no problems.

Thank you so much for the solution, it saved me a lot of time!

Just wanted to add that you can do the same with Npcap, modify the gopacket source code to point to Npcap and it will work too.

In case you don't know Npcap:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!