小結
總之,遇到問題記得先看 README.md / README.rst / README。
解決方式
在 linux/samples/bpf 這個資料夾裏面無法 build 出 sample 來
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
➜ bpf git:(master) ✗ make make –C ../../ $PWD/ make[1]: Entering directory ‘linux’ CHK include/config/kernel.release CHK include/generated/uapi/linux/version.h CHK include/generated/utsrelease.h CHK include/generated/timeconst.h CHK include/generated/bounds.h CHK include/generated/asm–offsets.h CALL scripts/checksyscalls.sh DESCEND objtool LD linux/samples/bpf/built–in.o HOSTCC linux/samples/bpf/test_verifier.o HOSTCC linux/samples/bpf/libbpf.o HOSTLD linux/samples/bpf/test_verifier HOSTCC linux/samples/bpf/test_maps.o HOSTLD linux/samples/bpf/test_maps HOSTCC linux/samples/bpf/sock_example.o HOSTLD linux/samples/bpf/sock_example HOSTCC linux/samples/bpf/bpf_load.o In file included from linux/samples/bpf/bpf_load.c:21:0: linux/samples/bpf/bpf_helpers.h:45:11: error: ‘BPF_FUNC_probe_write_user’ undeclared here (not in a function) (void *) BPF_FUNC_probe_write_user; ^~~~~~~~~~~~~~~~~~~~~~~~~ linux/samples/bpf/bpf_helpers.h:76:11: error: ‘BPF_FUNC_skb_under_cgroup’ undeclared here (not in a function) (void *) BPF_FUNC_skb_under_cgroup; ^~~~~~~~~~~~~~~~~~~~~~~~~ linux/samples/bpf/bpf_load.c: In function ‘load_and_attach’: linux/samples/bpf/bpf_load.c:71:15: error: ‘BPF_PROG_TYPE_XDP’ undeclared (first use in this function) prog_type = BPF_PROG_TYPE_XDP; ^~~~~~~~~~~~~~~~~ linux/samples/bpf/bpf_load.c:71:15: note: each undeclared identifier is reported only once for each function it appears in scripts/Makefile.host:124: recipe for target ‘linux/samples/bpf/bpf_load.o’ failed make[2]: *** [linux/samples/bpf/bpf_load.o] Error 1 Makefile:1639: recipe for target ‘linux/samples/bpf/’ failed make[1]: *** [linux/samples/bpf/] Error 2 make[1]: Leaving directory ‘linux’ Makefile:108: recipe for target ‘all’ failed make: *** [all] Error 2 |
把編譯器的錯誤丟到 google 上面去沒有找到結果:
1 2 3 4 5 6 7 8 9 10 11 |
search: error: ‘BPF_PROG_TYPE_XDP’ undeclared (first use in this function) result: 找不到符合搜尋字詞「error: ‘BPF_PROG_TYPE_XDP’ undeclared (first use in this function)」的文件。 建議: 請檢查有無錯別字 請換用不同的查詢字詞 請改試較常用的字詞 請減少查詢字詞 |
查看 README.rst,發現這段文字:
1 2 3 4 5 6 7 8 9 10 11 |
Kernel headers ——————— There are usually dependencies to header files of the current kernel. To avoid installing devel kernel headers system wide, as a normal user, simply call:: make headers_install This will creates a local “usr/include” directory in the git/build top level directory, that the make system automatically pickup first. |
照著指令先回到最上層,然後 sudo make headers_install
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
➜ linux git:(master) ✗ sudo make headers_install CHK include/generated/uapi/linux/version.h HOSTCC scripts/unifdef INSTALL usr/include/asm–generic/ (35 files) INSTALL usr/include/drm/ (21 files) INSTALL usr/include/linux/android/ (1 file) INSTALL usr/include/linux/byteorder/ (2 files) INSTALL usr/include/linux/caif/ (2 files) INSTALL usr/include/linux/can/ (5 files) INSTALL usr/include/linux/dvb/ (8 files) INSTALL usr/include/linux/hdlc/ (1 file) INSTALL usr/include/linux/hsi/ (2 files) INSTALL usr/include/linux/iio/ (2 files) INSTALL usr/include/linux/isdn/ (1 file) INSTALL usr/include/linux/mmc/ (1 file) INSTALL usr/include/linux/netfilter/ipset/ (4 files) INSTALL usr/include/linux/netfilter/ (86 files) INSTALL usr/include/linux/netfilter_arp/ (2 files) INSTALL usr/include/linux/netfilter_bridge/ (17 files) INSTALL usr/include/linux/netfilter_ipv4/ (9 files) INSTALL usr/include/linux/netfilter_ipv6/ (12 files) INSTALL usr/include/linux/nfsd/ (5 files) INSTALL usr/include/linux/raid/ (2 files) INSTALL usr/include/linux/spi/ (1 file) INSTALL usr/include/linux/sunrpc/ (1 file) INSTALL usr/include/linux/tc_act/ (12 files) INSTALL usr/include/linux/tc_ematch/ (4 files) INSTALL usr/include/linux/usb/ (11 files) INSTALL usr/include/linux/wimax/ (1 file) INSTALL usr/include/linux/ (432 files) INSTALL usr/include/misc/ (1 file) INSTALL usr/include/mtd/ (5 files) INSTALL usr/include/rdma/hfi/ (1 file) INSTALL usr/include/rdma/ (7 files) INSTALL usr/include/scsi/fc/ (4 files) INSTALL usr/include/scsi/ (4 files) INSTALL usr/include/sound/ (14 files) INSTALL usr/include/video/ (3 files) INSTALL usr/include/xen/ (4 files) INSTALL usr/include/uapi/ (0 file) INSTALL usr/include/asm/ (65 files) |
回到 samples/bpf 重新 make 一次,DONE!
Leave a Reply