Skip to main content
Version: v24.09

Build From Source on Linux

Prerequisites

In order to compile PcapPlusPlus on Linux please make sure you have the following components installed:

  1. libpcap developers pack - contains the libpcap library PcapPlusPlus is linking with and relevant the header files. You can download it from http://www.tcpdump.org/#latest-release or through the standard Linux package managers such as apt-get or yum:

    sudo apt-get install libpcap-dev

    or:

    sudo yum install libpcap-devel
  2. OPTIONAL - download and install Zstd if you wish to enable PCAPNG streaming compression support

Build

Assuming you want to build PcapPlusPlus into a build directory:

cmake -S . -B build

And then initiate the build in one of two ways:

  • Using CMake:
    cmake --build build
  • Using make:
    cd build
    make

This process will build the following artifacts:

  • PcapPlusPlus libs:
    • build/Common++/libCommon++.a
    • build/Packet++/libPacket++.a
    • build/Pcap++/libPcap++.a
  • PcapPlusPlus examples binaries under build/examples_bin
  • PcapPlusPlus tests:
    • <PcapPlusPlus_Dir>/Tests/Packet++Test/Bin/Packet++Test
    • <PcapPlusPlus_Dir>/Tests/Pcap++Test/Bin/Pcap++Test

The following configuration options are available (on top of CMake's built-in options):

OptionDescription
-DPCAPPP_BUILD_EXAMPLES=<ON/OFF>Build PcapPlusPlus examples (default value is ON if building the project itself, otherwise OFF)
-DPCAPPP_BUILD_TESTS=<ON/OFF>Build PcapPlusPlus tests (default value is ON if building the project itself, otherwise OFF)
-DPCAPPP_BUILD_TUTORIALS=<ON/OFF>Build PcapPlusPlus tutorials. This option is only available if DPCAPPP_BUILD_EXAMPLES=ON. The tutorials binaries will be under build/tutorials_bin (default value is OFF)
-DPCAPPP_INSTALL=<ON/OFF>Install PcapPlusPlus (default value is ON if building the project itself, otherwise OFF)
-DBUILD_SHARED_LIBS=<ON/OFF>Build shared libs (default value is OFF)
-DLIGHT_PCAPNG_ZSTD=<ON/OFF>Build with Zstd to enable PCAPNG streaming compression support (default value is OFF)
-DPCAPPP_ENABLE_PCAP_IMMEDIATE_MODE=<ON/OFF>Enable pcap immediate mode (default value is OFF)
-DPCAPPP_ENABLE_PCAP_SET_DIRECTION=<ON/OFF>Enable set direction for capturing incoming or outgoing packets (default value is OFF)
-DPCAPPP_USE_DPDK=<ON/OFF>Setup PcapPlusPlus with DPDK (default value is OFF). When this option is used CMake will look for an installed version of DPDK on the build machine (usually under /usr/local). If DPDK is installed in a different directory please use -DDPDK_ROOT
-DPCAPPP_USE_DPDK_KNI=<ON/OFF>Setup PcapPlusPlus with DPDK and KNI (default value is OFF). DPDK KNI is being deprecated in newer DPDK versions (>= 22.11), however PcapPlusPlus can still support it if using older DPDK versions when this option is used
-DDPDK_ROOT=<DIR>When setting up PcapPlusPlus with DPDK and DPDK is not installed in the defualt directory (usually under /usr/local) use this option to indicate DPDK installation directory
-DPCAPPP_USE_PF_RING=<ON/OFF>Setup PcapPlusplus with PF_RING (default value is OFF). When this option is used CMake will look for an installed version of PF_RING on the build machine (usually under /usr/local). If PF_RING is not installed please use -DPF_RING_ROOT
-DPF_RING_ROOT=<DIR>When setting up PcapPlusPlus with PF_RING and PF_RING is not installed on the machine use this option to indicate the PF_RING directory (for example /PF_RING)
-DPCAPPP_USE_XDP=<ON/OFF>Setup PcapPlusPlus with AF_XDP (default value is OFF). When this option is used CMake will look for an installed version of libbpf on the build machine

Installation

After the build is complete you can run the installation script which will copy the libraries, header files and examples into the installation directories:

sudo cmake --install .

If you want to install on a non-default directory you can use this command:

DESTDIR=<DIR> cmake --install build --prefix "/"

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.

Cross-compilation or build for different architectures

CMake supports cross compilation out-of-the-box so there is no need for any additional support in PcapPlusPlus.

Please refer to this page that provides information on how to cross compile with CMake: https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html