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:
- The fastest way I found for installing mingw32 was through this link: http://www.mingw.org/wiki/Getting_Started
- Download
mingw-get-setup.exe
, run it and follow the instructions - 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) - In the MinGW installation manager search for all packages containing
pthreads
and mark them for installation. Make sure thepthreads-win32
version you install is 2.10 or later - Choose
Installation->Update Catalogue
There is a bug in MinGW32 that makes PcapPlusPlus build to fail. Here is how to fix it:
- Go to the file:
YOUR_MINGW_INSTALL_PATH\MinGW\include\ptw32_errno.h
- 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) - Simply comment this line, like this:
//# include <winsock.h>
If you prefer to install pthreads manually please follow these steps
-
Download pthreads for MinGW
-
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 -
Copy the include files to MinGW folder:
xcopy /Y C:\pthreads\include\* C:\MinGW\include
-
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:
- Download and run mingw-w64 installer from here: https://sourceforge.net/projects/mingw-w64/
- Make sure the installation path doesn't contain spaces (otherwise PcapPlusPlus compilation may fail)
- 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) - Follow the instruction in the installation wizard
- Install
MSYS2
from here: https://www.msys2.org/ - Add the following folders to your
PATH
environment variable:- 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
- The MSYS2
usr\bin
folder, for example:C:\msys32\usr\bin
- The MinGW-w64 folder that contains
Additional prerequisites
- WinPcap developer's pack OR Npcap SDK - containing the
wpcap
library PcapPlusPlus is linking with plus relevanth
files.- WinPcap developer's pack can be downloaded from here: https://www.winpcap.org/devel.htm
- Npcap SDK can be downloaded from here: https://nmap.org/npcap/#download
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:
Option | Description |
---|---|
MINGW_COMPILER | MinGW compiler to use. Options are mingw32 or mingw-w64 |
-m , --mingw-home | MinGW home directory (the folder that includes bin , lib and include directories) |
-s , --msys-home | MSYS or MSYS2 home directory. Required only for MinGW-w64 |
-w , --pcap-sdk | Path to WinPcap Developer Pack (WpdPack) OR Npcap SDK |
-h , --help | Display 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:
- Run
mingw32-make.exe all
from PcapPlusPlus main directory - This should compile all libraries, unit-tests and examples
- To build the libraries only (without the unit-tests and examples) run
mingw32-make.exe libs
instead ofmingw32-make.exe all
- 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.