Skip to content

Instantly share code, notes, and snippets.

@krsna1729
Last active January 31, 2024 21:07
Show Gist options
  • Save krsna1729/91375dfcdfa15cb562b284f9e069d30c to your computer and use it in GitHub Desktop.
Save krsna1729/91375dfcdfa15cb562b284f9e069d30c to your computer and use it in GitHub Desktop.
compiling dpdk apps using cmake

Compiling DPDK and set environment var

cd dpdk
make config T=x86_64-native-linuxapp-gcc
make -j
export RTE_SDK=$(pwd)

Create CMakeLists.txt file for linking sample app with DPDK

cmake_minimum_required(VERSION 2.8)

SET(PRJ l2fwd)
PROJECT(${PRJ})

SET(SOURCE_EXE main.c)
SET(CMAKE_C_FLAGS "-Wall -Wextra -g -O3 -std=gnu11")

INCLUDE_DIRECTORIES($ENV{RTE_SDK}/build/include)
LINK_DIRECTORIES($ENV{RTE_SDK}/build/lib)

SET(DPDK_LIBS "-Wl,--whole-archive -ldpdk -Wl,--no-whole-archive")

ADD_EXECUTABLE(${PRJ} ${SOURCE_EXE})
TARGET_LINK_LIBRARIES(${PRJ} ${DPDK_LIBS})
TARGET_LINK_LIBRARIES(${PRJ} pthread dl rt m numa)

Run cmake

cmake .
-- The C compiler identification is GNU 6.3.1
-- The CXX compiler identification is GNU 6.3.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/stack/cmake_test

Now run make to build the executable using the generated Makefile

make

Scanning dependencies of target l2fwd
[ 50%] Building C object CMakeFiles/l2fwd.dir/main.c.o
[100%] Linking C executable l2fwd
[100%] Built target l2fwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment