如何使用cmake编译使用dpdk用C和C ++编写的项目

如何解决如何使用cmake编译使用dpdk用C和C ++编写的项目

我正在使用dpdk-stable-19.11.3,并且NIC是Mellaonx Connect5-X。项目的main函数是用C++编写的,但是它调用的所有其他函数都是用C编写的。我使用cmake来管理我的项目。我将所有C代码打包到一个静态库中。没有dpdk,就可以了。添加dpdk后,CMakeLists.txt似乎缺少一些库。它编译成功。但是,当运行可执行文件时,它将返回“打开文件错误”。然后,我添加了库rte_pmd_mlx5ibverbs。运行命令make时发生错误。

➜  build git:(master) ✗  make
-- Configuring done
-- Generating done
-- Build files have been written to: /home/hewen/demo/build
[ 83%] Built target mylib
[ 91%] Linking CXX executable demo
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dv_open_device':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:830: undefined reference to `mlx5dv_open_device'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_port_query':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:1030: undefined reference to `mlx5dv_query_devx_port'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_qp_query':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:1012: undefined reference to `mlx5dv_devx_qp_query'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_umem_dereg':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:999: undefined reference to `mlx5dv_devx_umem_dereg'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_umem_reg':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:984: undefined reference to `mlx5dv_devx_umem_reg'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_get_async_cmd_comp':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:969: undefined reference to `mlx5dv_devx_get_async_cmd_comp'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_obj_query_async':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:950: undefined reference to `mlx5dv_devx_obj_query_async'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_destroy_cmd_comp':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:937: undefined reference to `mlx5dv_devx_destroy_cmd_comp'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_create_cmd_comp':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:925: undefined reference to `mlx5dv_devx_create_cmd_comp'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_general_cmd':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:910: undefined reference to `mlx5dv_devx_general_cmd'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_obj_modify':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:893: undefined reference to `mlx5dv_devx_obj_modify'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_obj_query':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:876: undefined reference to `mlx5dv_devx_obj_query'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_obj_destroy':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:863: undefined reference to `mlx5dv_devx_obj_destroy'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_obj_create':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:847: undefined reference to `mlx5dv_devx_obj_create'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dv_destroy_flow_matcher':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:815: undefined reference to `mlx5dv_dr_matcher_destroy'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dv_destroy_flow':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:804: undefined reference to `mlx5dv_dr_rule_destroy'

...

/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:517: undefined reference to `mlx5dv_create_wq'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dv_create_cq':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:502: undefined reference to `mlx5dv_create_cq'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_destroy_domain':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:489: undefined reference to `mlx5dv_dr_domain_destroy'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_create_domain':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:476: undefined reference to `mlx5dv_dr_domain_create'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_destroy_flow_tbl':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:463: undefined reference to `mlx5dv_dr_table_destroy'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_create_flow_tbl':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:450: undefined reference to `mlx5dv_dr_table_create'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_create_flow_action_pop_vlan':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:439: undefined reference to `mlx5dv_dr_action_create_pop_vlan'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_create_flow_action_push_vlan':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:426: undefined reference to `mlx5dv_dr_action_create_push_vlan'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_create_flow_action_drop':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:414: undefined reference to `mlx5dv_dr_action_create_drop'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_create_flow_action_dest_port':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:397: undefined reference to `mlx5dv_dr_action_create_dest_ib_port'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_create_flow_action_dest_flow_tbl':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:385: undefined reference to `mlx5dv_dr_action_create_dest_table'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_destroy_flow_action':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:190: undefined reference to `mlx5dv_dr_action_destroy'
collect2: error: ld returned 1 exit status
CMakeFiles/demo.dir/build.make:95: recipe for target 'demo' failed
make[2]: *** [demo] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/demo.dir/all' failed

我有没有想念的库?这是我的CMakeLists.txt

cmake_minimum_required(VERSION 3.10)
project(myPJ LANGUAGES C CXX)

find_package(Threads REQUIRED)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_FLAGS "-msse4.2")
option(DEBUG "add complie options for gdb" ON)

set(RTE_SDK /home/hewen/dpdk-stable-19.11.3)
set(RTE_TARGET x86_64-native-linuxapp-gcc)
include_directories(${RTE_SDK}/${RTE_TARGET}/include)
link_directories(${RTE_SDK}/${RTE_TARGET}/lib)

include_directories(./tools)
link_directories("./tools/")

add_definitions(-pthread)
if(DEBUG)
    add_compile_options(-g -O0)
endif()

add_definitions(-DBUCKET_CLEANER)
add_definitions(-DCOLLECT_STATS -DTABLE_COLLECT_STATS -DLOG_COLLECT_STATS)
add_definitions(-DVERBOSE)

add_library(mylib STATIC a.c b.c c.c d.c)

add_executable(demo main.cpp)
target_link_libraries(demo PRIVATE mylib)
target_link_libraries(demo PRIVATE libxxhash.so)
target_link_libraries(demo PRIVATE Threads::Threads)
target_link_libraries(demo PRIVATE
        -Wl,--whole-archive    
            rte_ethdev
            rte_eal
            rte_mempool
            rte_pmd_mlx5
            ibverbs
            rte_pmd_e1000
            rte_pmd_i40e
            rte_pmd_ixgbe
            rte_pmd_virtio
            rte_pmd_vmxnet3_uio
            rte_hash
            rte_kvargs
            rte_bus_pci
            rte_pci
            rte_bus_vdev
            rte_mbuf
            rte_ring
            rte_net
            pthread
            dl            
            -Wl,--no-whole-archive
            numa
            rt
            pcap
            m
)

解决方法

如果使用自定义Makefile或CMakeLists.txt,则必须确保以下内容

  1. DPDK是使用适当的MXL5 PMD构建的
  2. 对于使用DPDK Makefile,添加到构建路径的库
EXTRA_CFLAGS=-I/path/to/rdma-core/build/include
EXTRA_LDFLAGS=-L/path/to/rdma-core/build/lib
PKG_CONFIG_PATH=/path/to/rdma-core/build/lib/pkgconfig
  1. 交叉检查并验证示例代码l2fwdskeleton是否有效。

注意:如评论中所述,检查很有用

[EDIT-1]按照注释中的更新,通过将mxl5库包含到CMakeLists.txt中,可以解决此问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-