Skip to main content
Version: v22.05

Build From Source on Windows - MinGW32 / MinGW-w64

Prerequisites for building with MinGW

In order to compile PcapPlusPlus on Windows using MinGW32 you need the following components:

  1. The fastest way I found for installing mingw32 was through this link: http://www.mingw.org/wiki/Getting_Started
  2. Download mingw-get-setup.exe, run it and follow the instructions
  3. By default the pthreads library is not installed so you need to ask to install it. It can be done during the installation process or afterwards with mingw-get.exe (MinGW installation manager)
  4. In the MinGW installation manager search for all packages containing pthreads and mark them for installation. Make sure the pthreads-win32 version you install is 2.10 or later
  5. Choose Installation->Update Catalogue
Notice

There is a bug in MinGW32 that makes PcapPlusPlus build to fail. Here is how to fix it:

  1. Go to the file: YOUR_MINGW_INSTALL_PATH\MinGW\include\ptw32_errno.h
  2. Search for the line that has #include <winsock.h>. You'll see a comment above this line saying this line is incompatible with any application which uses <winsock2.h> (PcapPlusPlus is one of them)
  3. Simply comment this line, like this: //# include <winsock.h>

If you prefer to install pthreads manually please follow these steps

  1. Download pthreads for MinGW

  2. Extract it with 7-Zip

    7z.exe e pthreads-GC-w32-2.10-mingw32-pre-20160821-1-dev.tar.xz -oC:\pthreads
    7z.exe x C:\pthreads\pthreads-GC-w32-2.10-mingw32-pre-20160821-1-dev.tar -oC:\pthreads
  3. Copy the include files to MinGW folder:

    xcopy /Y C:\pthreads\include\* C:\MinGW\include
  4. Copy the lib files to MinGW folder:

    xcopy /Y C:\pthreads\lib\* C:\MinGW\lib

Prerequisites for building with MinGW-w64

In order to compile PcapPlusPlus on Windows using MinGW-w64 you need the following components:

  1. Download and run mingw-w64 installer from here: https://sourceforge.net/projects/mingw-w64/
  2. Make sure the installation path doesn't contain spaces (otherwise PcapPlusPlus compilation may fail)
  3. Make sure to choose the i686 (32-bit) and POSIX threads (and not win32 threads) options. for example: i686-8.1.0-posix-dwarf-rt_v6-rev0. PcapPlusPlus doesn't support MinGW-w64 64-bit (x86_64)
  4. Follow the instruction in the installation wizard
  5. Install MSYS2from here: https://www.msys2.org/
  6. Add the following folders to your PATH environment variable:
    1. The MinGW-w64 folder that contains g++.exe, mingw32-make, etc. It should be under [MinGW-w64_install_folder]\mingw32\bin, for example: C:\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin
    2. The MSYS2 usr\bin folder, for example: C:\msys32\usr\bin

Additional prerequisites

  1. WinPcap developer's pack OR Npcap SDK - containing the wpcap library PcapPlusPlus is linking with plus relevant h files.
    1. WinPcap developer's pack can be downloaded from here: https://www.winpcap.org/devel.htm
    2. Npcap SDK can be downloaded from here: https://nmap.org/npcap/#download
x64 is not supported

Please notice that x64 compilation is not supported (and will not work) on either MinGW32 nor MinGW-w64!

Configuration

Run the configure-windows-mingw.bat batch file from PcapPlusPlus main directory. The script creates a makefile mk\PcapPlusPlus.mk that contains paths for 3rd-party libraries being used to build PcapPlusPlus.

Ths script has two modes of operation:

  • Wizard mode - the script will walk you through the paths and parameters you need to provide
  • Params mode - all parameters are provided in the script command line

In wizard mode the script will ask you for MinGW location (for example: C:\MinGW for MinGW or C:\i686-8.1.0-posix-dwarf-rt_v6-rev0 for MinGW-w64) and also for WinPcap developer's pack / Npcap SDK location (for example: C:\WpdPack or C:\Npcap-SDK).

Here is an example of running the script for MinGW32:

C:\PcapPlusPlus>configure-windows-mingw.bat

******************************************
PcapPlusPlus Windows configuration script
******************************************

MinGW32 or MinGW-w64 are required for compiling PcapPlusPlus. Please specify
the type you want to use (can be either "mingw32" or "mingw-w64")

Please specify mingw32 or mingw-w64: mingw32


If mingw32 is not installed, please download and install it
mingw32 can be downloaded from: www.mingw.org/

Please specify mingw32 installed path (for example: C:\MinGW or C:\i686-8.1.0-posix-dwarf-rt_v6-rev0): C:\MinGW


WinPcap or Npcap SDK is required for compiling PcapPlusPlus.
For downloading WinPcap SDK (developer's pack) please go to https://www.winpcap.org/devel.htm
For downloading Npcap SDK please go to https://nmap.org/npcap/#download

Please specify WinPcap/Npcap SDK path: C:\WpdPack

PcapPlusPlus configuration is complete. Files created (or modified): mk\platform.mk, mk\PcapPlusPlus.mk

Here is another example of running the script for MinGW-w64:

C:\PcapPlusPlus>configure-windows-mingw.bat

******************************************
PcapPlusPlus Windows configuration script
******************************************

MinGW32 or MinGW-w64 are required for compiling PcapPlusPlus. Please specify
the type you want to use (can be either "mingw32" or "mingw-w64")

Please specify mingw32 or mingw-w64: mingw-w64


If mingw-w64 is not installed, please download and install it
mingw-w64 can be downloaded from: sourceforge.net/projects/mingw-w64/

Please specify mingw-w64 installed path (for example: C:\MinGW or C:\i686-8.1.0-posix-dwarf-rt_v6-rev0): C:\i686-8.1.0-posix-dwarf-rt_v6-rev0


MSYS2 is required for compiling PcapPlusPlus.
If MSYS2 are not installed, please download and install it from: https://www.msys2.org/

Please specify MSYS2 installed path: C:\msys64


WinPcap or Npcap SDK is required for compiling PcapPlusPlus.
For downloading WinPcap SDK (developer's pack) please go to https://www.winpcap.org/devel.htm
For downloading Npcap SDK please go to https://nmap.org/npcap/#download

Please specify WinPcap/Npcap SDK path: C:\Npcap-SDK

PcapPlusPlus configuration is complete. Files created (or modified): mk\platform.mk, mk\PcapPlusPlus.mk

In params mode you need to provide these paths as script params. You can use the --help switch to query these params:

C:\PcapPlusPlus>configure-windows-mingw.bat --help

******************************************
PcapPlusPlus Windows configuration script
******************************************


Help documentation for configure-windows-mingw.bat
This script has 2 modes of operation:
1) Without any switches. In this case the script will guide you through using wizards
2) With switches, as described below

Basic usage: configure-windows-mingw.bat [-h] MINGW_COMPILER -m MINGW_HOME_DIR -w PCAP_SDK_DIR [-s MSYS_HOME_DIR]

The following switches are recognized:
MINGW_COMPILER --The MinGW compiler to use. Can be either "mingw32" or "mingw-w64"
-m|--mingw-home --Set MinGW home directory (the folder that includes "bin", "lib" and "include" directories)
-s|--msys-home --Set MSYS2 home directory (must for mingw-w64, not must for mingw32)
-w|--pcap-sdk --Set WinPcap/Npcap SDK directory
-h|--help --Display this help message and exits. No further actions are performed

For example (MinGW32):

C:\PcapPlusPlus>configure-windows-mingw.bat mingw32 --mingw-home C:\MinGW --pcap-sdk C:\Npcap-SDK

******************************************
PcapPlusPlus Windows configuration script
******************************************


PcapPlusPlus configuration is complete. Files created (or modified): mk\platform.mk, mk\PcapPlusPlus.mk

Or (MinGW-w64):

C:\PcapPlusPlus>configure-windows-mingw.bat mingw-w64 --mingw-home C:\i686-8.1.0-posix-dwarf-rt_v6-rev0 --msys-home C:\msys64 --pcap-sdk C:\WpdPack

******************************************
PcapPlusPlus Windows configuration script
******************************************


PcapPlusPlus configuration is complete. Files created (or modified): mk\platform.mk, mk\PcapPlusPlus.mk

Here are the available switches:

OptionDescription
MINGW_COMPILERMinGW compiler to use. Options are mingw32 or mingw-w64
-m , --mingw-homeMinGW home directory (the folder that includes bin, lib and include directories)
-s , --msys-homeMSYS or MSYS2 home directory. Required only for MinGW-w64
-w , --pcap-sdkPath to WinPcap Developer Pack (WpdPack) OR Npcap SDK
-h , --helpDisplay the help message and exit. No further actions are performed

Build the code

After running the config script, you're can safely build the code:

  1. Run mingw32-make.exe all from PcapPlusPlus main directory
  2. This should compile all libraries, unit-tests and examples
  3. To build the libraries only (without the unit-tests and examples) run mingw32-make.exe libs instead of mingw32-make.exe all
  4. After compilation you can find the libraries, examples, header files and helpful makefiles under the Dist\ directory

Running tests

PcapPlusPlus contains a set of test-cases you can run to make sure that everything works correctly on your system. This guide contains detailed instructions on how to run them.