声明:本文中的所有命令运行均在ubuntu-20.04
kselftest是Linux kernel自带的一个自动化测试套件. 首次运行make kselftest-install 通常会报错。为解决该问题,运行如下命令:
$ make kselftest-install 2>err_make.txt
其中这里2是stderr的文件描述符,表示在运行前面的命令的时候把error信息都写在文件err_make.txt (新建或覆盖方式)。
运行完后,打开err_make.txt文件,显示
make[2]: *** [bpf/Makefile:12: /home/minipc/stable_rc/linux-5.19.0/tools/testing/selftests/net/bpf/nat6to4.o] Error 1
/bin/sh: 1: llc: not found
/bin/sh: 3: llc: not found
make[2]: *** [Makefile:27: /home/minipc/stable_rc/linux-5.19.0/tools/testing/selftests/tc-testing/action.o] Error 127
/usr/bin/ld: cannot find -lpopt
collect2: error: ld returned 1 exit status
make[2]: *** [../lib.mk:173: /home/minipc/stable_rc/linux-5.19.0/tools/testing/selftests/mqueue/mq_open_tests] Error 1
In file included from bpf/nat6to4.c:43:
../../../lib/bpf/bpf_helpers.h:11:10: fatal error: 'bpf_helper_defs.h' file not found
#include "bpf_he/usr/bin/ld: cannot find -lpopt
collect2: error: ld returned 1 exit status
make[2]: *** [../lib.mk:173: /home/minipc/stable_rc/linux-5.19.0/tools/testing/selftests/mqueue/mq_open_tests] Error 1
In file included from bpf/nat6to4.c:43:
../../../lib/bpf/bpf_helpers.h:11:10: fatal error: 'bpf_helper_defs.h' file not found
#include "bpf_helper_defs.h"
^~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [bpf/Makefile:12: /home/minipc/stable_rc/linux-5.19.0/tools/testing/selftests/net/bpf/nat6to4.o] Error 1
/bin/sh: 1: llc: not found
/bin/sh: 3: llc: not found
make[2]: *** [Makefile:27: /home/minipc/stable_rc/linux-5.19.0/tools/testing/selftests/tc-testing/action.o] Error 127
/usr/bin/ld: cannot find -lpopt
collect2: error: ld returned 1 exit status
make[2]: *** [../lib.mk:173: /home/minipc/stable_rc/linux-5.19.0/tools/testing/selftests/mqueue/mq_open_tests] Error 1
In file included from bpf/nat6to4.c:43:
../../../lib/bpf/bpf_helpers.h:11:10: fatal error: 'bpf_helper_defs.h' file not found
#include "bpf_helper_defs.h"
^~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [bpf/Makefile:12: /home/minipc/stable_rc/linux-5.19.0/tools/testing/selftests/net/bpf/nat6to4.o] Error 1
/bin/sh: 1: llc: not found
/bin/sh: 3: llc: not found
make[2]: *** [Makefile:27: /home/minipc/stable_rc/linux-5.19.0/tools/testing/selftests/tc-testing/action.o] Error 127
err_make.txt.1 (END)
这里我们一个个分析:
1. /bin/sh: 1: llc: not found 和 /bin/sh: 3: llc: not found 表示sh不能识别llc 命令
$ llc
Command 'llc' not found, but can be installed with:
sudo apt install llvm
按提示安装llvm包
$ sudo apt install llvm
安装完成后,运行which llc
$ which llc
/usr/bin/llc
说明llc已经安装好了
2. /usr/bin/ld: cannot find -lpopt 表明链接(Linker)发现缺少库文件,形式为lxxx,l代表library, 这里表示popt库缺失,运行如下命令安装
$sudo apt-get install libpopt-dev
3. ../../../lib/bpf/bpf_helpers.h:11:10: fatal error: 'bpf_helper_defs.h' file not found
这表示bpf_helpers.h文件中引用了一个缺失的头文件。在kernel的source根目录下查找该文件
$ find -name bpf_helper_defs.h
./tools/bpf/resolve_btfids/libbpf/include/bpf/bpf_helper_defs.h
./tools/bpf/resolve_btfids/libbpf/bpf_helper_defs.h
发现这个文件存在,只是和上面的bpf_helpers.h不在一个目录下。一个简单的处理方法就是把该文件拷到和它一个目录下,如:
$cp ./tools/bpf/resolve_btfids/libbpf/include/bpf/bpf_helper_defs.h ./tools/lib/bpf/
以上都操作完后,再次运行
$ make kselftest-install 2>err_make.txt
发现err_make.txt文件为空。
总结,(1)缺少命令,安装含该命令的包;(2)缺少库,安装相应的库;(3)缺少头文件,先在内部找,如果有,拷贝到需要的目录。