Home > Backend Development > Golang > How to Compile Gopacket on Windows 64-bit with \'File in Wrong Format\' Error?

How to Compile Gopacket on Windows 64-bit with \'File in Wrong Format\' Error?

Linda Hamilton
Release: 2024-10-29 12:51:29
Original
614 people have browsed it

How to Compile Gopacket on Windows 64-bit with

Compiling Gopacket on Windows 64-bit

Problem:

When attempting to compile gopacket on Windows 10 for 64-bit (GOARCH=amd64), an error occurs indicating "File in wrong format" when adding wpcap symbols to the binary.

Solution:

To compile gopacket on Windows 64-bit successfully, follow these steps:

  1. Install Go for 64-bit (go_amd64).
  2. Install TDM GCC x64 and add its binaries to the PATH variable.
  3. Add the TDM-GCC x86_64-w64-mingw32bin directory to the PATH variable.
  4. Install Winpcap.
  5. Download the Winpcap developer's pack and extract it to C:.

As the Winpcap developer's pack lacks Linux static libraries (libwpcap.a and libpacket.a), generate them manually:

  1. Copy wpcap.dll and packet.dll to a temporary folder.
  2. Run gendef on both files to generate .def files.
  3. Generate the static libraries using dlltool with the following commands:
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
Copy after login
  1. Copy libwpcap.a and libpacket.a to C:WpdPackLibx64.

With these steps completed, gopacket should compile without errors on Windows 64-bit.

The above is the detailed content of How to Compile Gopacket on Windows 64-bit with \'File in Wrong Format\' Error?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template