DPDK Example Application 编译错误缺少库文件

DPDK Example Application Compilation error missing library files

我正在尝试使用以下方法编译 dpdk 示例应用程序 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} )

出现编译错误

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

以前的 dpdk 版本中缺少 .so 文件。我需要使用更新版本的 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

我的 system.19.11 和 dpdk-stable-20.11 中有 2 个版本的 dpdk。目前使用 dpdk-stable-20.11 尝试使用示例应用程序附带的默认 Makefile。上面提到的库文件丢失错误并没有发生。

带有默认 Makefile 的 Basicfwd

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

我需要在 CMakeLists.txt 中做任何修改吗?请提供解决此问题的建议

编辑: 我修改了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})

出现编译错误

> -- 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

请提出解决此问题的建议

这不是 DPDK 示例或 pkg-config 相关问题,而是与 CMAKE 使用相关。根据习俗 CMakelist.txt,缺少 link_directories /usr/local/lib/aarch64-linux-gnu。如果 DPDK 如前所述构建并安装了库,则需要将其添加到 CMakelis.txt

在我看来,如果存在 DPDK,应该首先尝试使用 pkg-config。如果是,使用cmake supported _CFLAGS and _LDFLAGS解决依赖关系

示例代码

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

[Edit-2] 基于共享的 compilation error 信息

对于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]

基于有限的日志错误原因you are trying a cross-build, but the CMakeLists.txt is not having the same。对于使用 CMAKE 进行交叉编译,应该使用 CMAKE 方法和选项,例如 cmake -DCMAKE_TOOLCHAIN_FILE=[target tool chain root folder]/toolchain.cmake ..。 B