asm/types.h 编译 ebpf 代码时出错

asm/types.h Error during compilation of ebpf code

提问人:Rohan Aluguri 提问时间:11/9/2023 更新时间:11/11/2023 访问量:47

问:

在这里,我正在尝试编译 eBPF 代码。并使用以下命令进行编译。 命令:clang -O2 -target bpf -c your_ebpf_program.c -o your_ebpf_program.o

错误:在 my_program.c:2:/usr/include/linux/bpf.h:11:10 包含的文件中:致命错误:未找到“asm/types.h”文件#include <asm/types.h> ^~~~~~~~~~~~~1 错误。

我使用 clang 作为编译器进行编译。所有必需的库都已下载,但出现错误,指出找不到 asm/types.h。所有 linux 头文件均已更新。

叮当 EBPF XDP-BPF BCC-BPF

评论


答:

2赞 Dylan Reimerink 11/11/2023 #1

您可能需要安装其他内核头文件。例如,在 Ubuntu 上,您可以通过执行

apt install linux-headers-`uname -r`

显然,在某些平台上,您可能还需要符号链接目录。但我不确定这是否总是必需的。来源 1 来源 2

sudo ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/asm