linux@linux-virtual-machine:~/Desktop/w13_x86_EP$ make
make -C /lib/modules/5.4.0-70-generic/build M=/home/linux/Desktop/w13_x86_EP
make[1]: Entering directory '/usr/src/linux-headers-5.4.0-70-generic'
AR /home/linux/Desktop/w13_x86_EP/built-in.a
CC [M] /home/linux/Desktop/w13_x86_EP/hello_pcie.o
In file included from ./include/asm-generic/int-ll64.h:11:0,
from ./arch/arm/include/uapi/asm/types.h:5,
from ./include/uapi/linux/types.h:5,
from ./include/linux/types.h:6,
from ./include/linux/limits.h:6,
from ./include/linux/kernel.h:7,
from /home/linux/Desktop/w13_x86_EP/hello_pcie.c:1:
./include/uapi/asm-generic/int-ll64.h:12:29: fatal error: asm/bitsperlong.h: No such file or directory
#include <asm/bitsperlong.h>
^
compilation terminated.
scripts/Makefile.build:269: recipe for target '/home/linux/Desktop/w13_x86_EP/hello_pcie.o' failed
make[2]: *** [/home/linux/Desktop/w13_x86_EP/hello_pcie.o] Error 1
Makefile:1760: recipe for target '/home/linux/Desktop/w13_x86_EP' failed
make[1]: *** [/home/linux/Desktop/w13_x86_EP] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-70-generic'
Makefile:7: recipe for target 'all' failed
make: *** [all] Error 2
原因分析:
当前是要编译一个 X86 端运行的内核模块,但在编译日志中出现了 arm 相关字段,因此应该是 ARCH 和 CROSS_COMPILE 设置的不对。
经过检查,发现在 ~/.bashrc 文件中将 ARCH 和 CROSS_COMPILE 配置成了 ARM 开发板的编译选项。将该配置去掉之后,问题消失,编译通过。