由于符号链接冲突而无法编译内核模块

由于符号链接冲突而无法编译内核模块

我正在尝试编译一个最小的内核模块,如下所示:

# cat Makefile
obj-m += mymodule.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

这样做时,我遇到一个错误,指出它找不到头文件。所以我创建了一个符号链接,解决了这个问题。但后来我在另一个头文件中遇到了同样的问题,而且我无法创建 1 个 simlink 到 2 个不同的地方。是我的理解不正确还是你如何解决这个问题?

root@system-yocto:~/kernelModule# make -j
make -C /lib/modules/5.15.54-yocto-standard/build M=/home/root/kernelModule modules
make[1]: Entering directory '/lib/modules/5.15.54-yocto-standard/build'
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: arm-poky-linux-gnueabi-gcc (GCC) 11.4.0
  You are using:           gcc (GCC) 11.4.0
  CC [M]  /home/root/kernelModule/mymodule.o
In file included from ./include/linux/init.h:5,
                 from /home/root/kernelModule/mymodule.c:1:
./include/linux/compiler.h:255:10: fatal error: asm/rwonce.h: No such file or directory
  255 | #include <asm/rwonce.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [scripts/Makefile.build:288: /home/root/kernelModule/mymodule.o] Error 1
make[1]: *** [Makefile:1886: /home/root/kernelModule] Error 2
make[1]: Leaving directory '/lib/modules/5.15.54-yocto-standard/build'
make: *** [Makefile:4: all] Error 2
root@system-yocto:~/kernelModule# ls -l /lib/modules/5.15.54-yocto-standard/source/include/
total 204
drwxr-xr-x  3 root root  4096 Mar  9 12:34 acpi
drwxr-xr-x  4 root root  4096 Mar  9 12:42 asm-generic
drwxr-xr-x  2 root root  4096 Mar  9 12:34 clocksource
drwxr-xr-x  2 root root 53248 Mar  9 12:34 config
drwxr-xr-x  3 root root  4096 Mar  9 12:34 crypto
drwxr-xr-x  5 root root  4096 Mar  9 12:34 drm
drwxr-xr-x 37 root root  4096 Mar  9 12:34 dt-bindings
drwxr-xr-x  3 root root  4096 Mar  9 12:34 generated
drwxr-xr-x  2 root root  4096 Mar  9 12:34 keys
drwxr-xr-x  2 root root  4096 Mar  9 12:34 kunit
drwxr-xr-x  2 root root  4096 Mar  9 12:34 kvm
drwxr-xr-x 65 root root 40960 Mar  9 12:34 linux
drwxr-xr-x  2 root root  4096 Mar  9 12:34 math-emu
drwxr-xr-x  6 root root  4096 Mar  9 12:34 media
drwxr-xr-x  2 root root  4096 Mar  9 12:34 memory
drwxr-xr-x  2 root root  4096 Mar  9 12:34 misc
drwxr-xr-x 12 root root  4096 Mar  9 12:34 net
drwxr-xr-x  2 root root  4096 Mar  9 12:34 pcmcia
drwxr-xr-x  2 root root  4096 Mar  9 12:34 ras
drwxr-xr-x  2 root root  4096 Mar  9 12:34 rdma
drwxr-xr-x  3 root root  4096 Mar  9 12:34 scsi
drwxr-xr-x 16 root root  4096 Mar  9 12:34 soc
drwxr-xr-x  4 root root  4096 Mar  9 12:34 sound
drwxr-xr-x  3 root root  4096 Mar  9 12:34 target
drwxr-xr-x  3 root root  4096 Mar  9 12:34 trace
drwxr-xr-x 12 root root  4096 Mar  9 12:34 uapi
drwxr-xr-x  2 root root  4096 Mar  9 12:34 vdso
drwxr-xr-x  2 root root  4096 Mar  9 12:34 video
drwxr-xr-x  4 root root  4096 Mar  9 12:34 xen
root@system-yocto:~/kernelModule# ln -s /lib/modules/5.15.54-yocto-standard/source/include/asm-generic/ /lib/modules/5.15.54-yocto-standard/source/include/asm
root@system-yocto:~/kernelModule# make -j
make -C /lib/modules/5.15.54-yocto-standard/build M=/home/root/kernelModule modules
make[1]: Entering directory '/lib/modules/5.15.54-yocto-standard/build'
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: arm-poky-linux-gnueabi-gcc (GCC) 11.4.0
  You are using:           gcc (GCC) 11.4.0
  CC [M]  /home/root/kernelModule/mymodule.o
In file included from ./include/linux/errno.h:5,
                 from ./include/linux/string.h:8,
                 from ./include/linux/bitmap.h:10,
                 from ./include/linux/cpumask.h:12,
                 from ./include/linux/mm_types_task.h:14,
                 from ./include/linux/mm_types.h:5,
                 from ./include/linux/buildid.h:5,
                 from ./include/linux/module.h:14,
                 from /home/root/kernelModule/mymodule.c:2:
./include/uapi/linux/errno.h:1:10: fatal error: asm/errno.h: No such file or directory
    1 | #include <asm/errno.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [scripts/Makefile.build:288: /home/root/kernelModule/mymodule.o] Error 1
make[1]: *** [Makefile:1886: /home/root/kernelModule] Error 2
make[1]: Leaving directory '/lib/modules/5.15.54-yocto-standard/build'
make: *** [Makefile:4: all] Error 2

相关内容