【发布时间】:2019-07-16 06:02:55
【问题描述】:
最近一直在研究BPF,但是因为一个很基础的问题没有继续下去。
我按照 man bpf(2) 中的描述包含了 linux/bpf.h,但是 GCC 找不到 bpf 函数。这段代码只是为了测试确保GCC可以找到bpf函数。
#include <linux/bpf.h>
int main()
{
bpf(0,(void *)0,0);
return 0;
}
GCC 输出是这样的。
$ gcc -o test bpf.c
bpf.c: In function ‘main’:
bpf.c:5:2: warning: implicit declaration of function ‘bpf’ [-Wimplicit-function-declaration]
bpf(0,(void *)0,0);
^~~
/usr/bin/ld: /tmp/cc4tjrUh.o: in function `main':
bpf.c:(.text+0x19): undefined reference to `bpf'
collect2: error: ld returned 1 exit status
我使用的是 Archlinux,linux 内核版本是 4.20.11-arch1-1-ARCH。 请帮助我如何包含 bpf 功能。
【问题讨论】: