Search code examples
cmakedpdk

DPDK Example Application Compilation error missing library files


I am trying to compile dpdk sample application using following CMakelist.txt

cmake_minimum_required(VERSION 3.10)
link_directories(/usr/local/lib/aarch64-linux-gnu/)
include_directories(/usr/local/include)
SET(DPDK_LIBS "-Wl,--whole-archive  -l dpdk  -Wl,--no-whole-archive")
add_executable(basicfwd  basicfwd.c )
target_link_libraries(basicfwd LINK_PUBLIC  ${DPDK_LIBS} )

Compilation Error occurs

Scanning dependencies of target basicfwd
[ 50%] Building C object CMakeFiles/basicfwd.dir/basicfwd.c.o
[100%] Linking C executable basicfwd 
/usr/bin/ld: cannot find librte_pmd_bbdev_fpga_lte_fec.so
/usr/bin/ld: cannot find librte_pmd_bbdev_turbo_sw.so 
/usr/bin/ld: cannot find librte_pmd_hinic.so 
/usr/bin/ld: cannot find librte_pmd_hns3.so 
/usr/bin/ld: cannot find librte_pmd_iavf.so
/usr/bin/ld: cannot find librte_pmd_ice.so 
/usr/bin/ld: cannot find librte_pmd_lio.so
/usr/bin/ld: cannot find librte_pmd_memif.so
/usr/bin/ld: cannot find librte_pmd_nitrox.so
/usr/bin/ld: cannot find librte_pmd_octeontx2.so 
/usr/bin/ld: cannot find librte_pmd_octeontx2_crypto.so 
/usr/bin/ld: cannot find librte_pmd_octeontx2_event.so 
 usr/bin/ld: cannot find librte_pmd_octeontx_ssovf.so
/usr/bin/ld: cannot find librte_pmd_octeontx_zip.so 
/usr/bin/ld: cannot find librte_pmd_pfe.so
/usr/bin/ld: cannot find librte_pmd_thunderx_nicvf.so 
/usr/bin/ld: cannot find librte_pmd_vmxnet3_uio.so 
/usr/bin/ld: cannot find librte_rawdev_dpaa2_cmdif.so 
/usr/bin/ld: cannot find librte_rawdev_dpaa2_qdma.so 
/usr/bin/ld: cannot find librte_rawdev_ntb.so 
/usr/bin/ld: cannot find librte_rawdev_octeontx2_dma.so 
/usr/bin/ld: cannot find librte_rawdev_skeleton.so 
collect2: error: ld returned 1 exit status
CMakeFiles/basicfwd.dir/build.make:94: recipe for target 'basicfwd' failed 
make[2]: *** [basicfwd] Error 1 
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/basicfwd.dir/all' failed 
make[1]: *** [CMakeFiles/basicfwd.dir/all] Error 2 
Makefile:83: recipe for target 'all' failed 
make: *** [all] Error 2

Missing .so files are available in previous dpdk version. I need to use newer version of dpdk.

#locate librte_rawdev_ntb.so
/opt/dpdk/lib/librte_rawdev_ntb.so
/opt/dpdk/lib/librte_rawdev_ntb.so.20.0
# locate librte_pmd_ice.so
/opt/dpdk/lib/librte_pmd_ice.so
/opt/dpdk/lib/librte_pmd_ice.so.20.0

I have 2 versions of dpdk in my system.19.11 and dpdk-stable-20.11. Currently using dpdk-stable-20.11 Tried with default Makefile that comes with sample application. Above mentioned library file missing error is not happening.

Basicfwd with default Makefile

cc -O3 -include rte_config.h -mcpu=cortex-a72 -I/usr/local/include -I/usr/include/libnl3 -DALLOW_EXPERIMENTAL_API basicfwd.c -o build/basicfwd-shared  -L/usr/local/lib/aarch64-linux-gnu -Wl,--as-needed -lrte_node -lrte_graph -lrte_bpf -lrte_flow_classify -lrte_pipeline -lrte_table -lrte_port -lrte_fib -lrte_ipsec -lrte_vhost -lrte_stack -lrte_security -lrte_sched -lrte_reorder -lrte_rib -lrte_regexdev -lrte_rawdev -lrte_pdump -lrte_power -lrte_member -lrte_lpm -lrte_latencystats -lrte_kni -lrte_jobstats -lrte_ip_frag -lrte_gso -lrte_gro -lrte_eventdev -lrte_efd -lrte_distributor -lrte_cryptodev -lrte_compressdev -lrte_cfgfile -lrte_bitratestats -lrte_bbdev -lrte_acl -lrte_timer -lrte_hash -lrte_metrics -lrte_cmdline -lrte_pci -lrte_ethdev -lrte_meter -lrte_net -lrte_mbuf -lrte_mempool -lrte_rcu -lrte_ring -lrte_eal -lrte_telemetry -lrte_kvargs -lbsd
ln -sf basicfwd-shared build/basicfwd

Do I need to do any modification in CMakeLists.txt. Please provide suggestions to resolve this

Edit: I have modified CMakeList.txt

cmake_minimum_required(VERSION 3.10)
# the `pkg_check_modules` function is created with this call
find_package(PkgConfig REQUIRED)
pkg_check_modules(DPDK_LIB REQUIRED libdpdk)
add_executable(basicfwd  basicfwd.c )
target_link_libraries(basicfwd ${DPDK_LIB_LIBRARIES})
target_include_directories(basicfwd PUBLIC ${DPDK_LIB__INCLUDE_DIRS})
target_compile_options(basicfwd PUBLIC ${DPDK_LIB_CFLAGS_OTHER})

Compilation Error occurs

> -- Checking for module 'libdpdk'
> --   Found libdpdk, version 20.11.1
> -- Configuring done
> -- Generating done
> -- Build files have been written to: /home/ubuntu/Sample/build /home/ubuntu/Sample/build# make Scanning dependencies of target
> basicfwd [ 50%] Building C object CMakeFiles/basicfwd.dir/basicfwd.c.o
> [100%] Linking C executable basicfwd
> CMakeFiles/basicfwd.dir/basicfwd.c.o: In function `main':
> basicfwd.c:(.text+0x15fc): undefined reference to `rte_lcore_count'
> collect2: error: ld returned 1 exit status
> CMakeFiles/basicfwd.dir/build.make:94: recipe for target 'basicfwd'
> failed make[2]: *** [basicfwd] Error 1 CMakeFiles/Makefile2:67: recipe
> for target 'CMakeFiles/basicfwd.dir/all' failed make[1]: ***
> [CMakeFiles/basicfwd.dir/all] Error 2 Makefile:83: recipe for target
> 'all' failed make: *** [all] Error 2

Please give suggestions to resolve this


Solution

  • This is not DPDK example or pkg-config related issue, but this is related to CMAKE usage. Based on the custom CMakelist.txt the link_directories is missing /usr/local/lib/aarch64-linux-gnu. If DPDK build and installed the libraries as mentioned you will need to add the same to CMakelis.txt

    In my opinion one should first try to use pkg-config if DPDK exisit. If yes, use cmake supported _CFLAGS and _LDFLAGS to solve the dependencies.

    sample code

    add_definitions(${DPDK_CFLAGS}
    include_directories(${DPDK_INCLUDE_DIR})
    link_libraries(${MYDPDK_LIBRARIES})
    add_definitions(-DHAVE_DPDK)
    

    [Edit-2] based on the compilation error information shared

    For native build

    CMake Error: CMake can not determine linker language for target: basicfwd
    CMake Error: Cannot determine link language for target "basicfwd".
    -- Generating done
    -- Build files have been written to: /tmp/cmaketest/build
    
    $ make
    Scanning dependencies of target basicfwd
    [ 50%] Building C object CMakeFiles/basicfwd.dir/basicfwd.c.o
    [100%] Linking C executable basicfwd
    [100%] Built target basicfwd
    
    $ sudo ./basicfwd --no-pci --vdev=net_tap0  --vdev=net_tap1
    EAL: Detected 32 lcore(s)
    EAL: Detected 2 NUMA nodes
    EAL: Detected shared linkage of DPDK
    EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
    EAL: Selected IOVA mode 'VA'
    EAL: Probing VFIO support...
    EAL: No legacy callbacks, legacy socket not created
    Port 0 MAC: a6 1a ac 56 7f a8
    Port 1 MAC: be 52 49 67 d3 fa
    
    WARNING: Too many lcores enabled. Only 1 used.
    
    Core 0 forwarding packets. [Ctrl+C to quit]
    

    Based on the limited log cause of error you are trying a cross-build, but the CMakeLists.txt is not having the same. For cross compiling with CMAKE one should use CMAKE method and option such as cmake -DCMAKE_TOOLCHAIN_FILE=[target tool chain root folder]/toolchain.cmake ... B