项目场景:
使用 QEMU 仿真测试 CXL2.0 设备
项目地址(网络大佬开源项目):https://github.com/linuslau/CXL-Emulator-QEMU
问题描述
在编译ndctl工具源码时,出现头文件不兼容问题,如下图所示:

[1/80] Compiling C object test/fwctl.p/fwctl.c.o FAILED: test/fwctl.p/fwctl.c.o cc -Itest/fwctl.p -Itest -I../test -I. -I.. -Indctl -I../ndctl -I/usr/include/uuid -fdiagnostics-coloc In file included from ../test/fwctl.c:17: ../cxl/fwctl/features.h:108:9: error: expected specifier-qualifier-list before ‘__struct_group’ 108 | __struct_group(cxl_mbox_get_sup_feats_out_hdr, hdr, /* no attrs */, | ^~~~~~~~~~~~~~ ../cxl/fwctl/features.h:162:9: error: expected specifier-qualifier-list before ‘__struct_group’ 162 | __struct_group(cxl_mbox_set_feat_hdr, hdr, /* no attrs */, | ^~~~~~~~~~~~~~ In file included from ../test/fwctl.c:19: ../cxl/fwctl/cxl.h:25:9: error: expected specifier-qualifier-list before ‘__struct_group’ 25 | __struct_group(fwctl_rpc_cxl_hdr, hdr, /* no attrs */, | ^~~~~~~~~~~~~~ ../cxl/fwctl/cxl.h:46:9: error: expected specifier-qualifier-list before ‘__struct_group’
原因分析:
查看我的宿主机Ubuntu为24.04,内核版本为6.14.0,客户机安装的Ubuntu为22.04,默认内核版本为5.15.0。虽然升级到6.8.0运行内核为6.8.0,但apt仓库内核还为5.15.0。导致内核头文件里找不到对应的__struct_group结构体,编译报错。

解决方案:
升级内核头文件:
1、首先检查仓库源列表是否完整:
vim /etc/apt/sources.list
确保至少包含这些行(以 Ubuntu 22.04 为例):
deb http://archive.ubuntu.com/ubuntu jammy main universe restricted multiverse
deb http://archive.ubuntu.com/ubuntu jammy-updates main universe restricted multiverse
deb http://archive.ubuntu.com/ubuntu jammy-security main universe restricted multiverse
2、安装与 6.8.x 匹配的 HWE 头文件包:
apt update
apt install linux-headers-generic-hwe-22.04
这个包会拉取 linux-headers-6.8.x 系列
3、检查是否成功:
dpkg -l | grep linux-headers
有输出表示,升级成功了。
最后,再编译ndctl工具便可以完成编译。
1321

被折叠的 条评论
为什么被折叠?



