我有一个外部内核模块和一个 Makefile。我之前使用 Kbuild,但决定直接使用 Makefile 和 make。我安装了标头、build-essential 和 kmod,到目前为止,我遇到了 .h 文件的问题。
我有外部内核模块的 .c 到 .o 文件。到目前为止,问题与 .h 文件有关。我无法编译它。
以下是我的简单 Makefile:
# Some random Kernel Module Course Online
# KDIR += /lib/modules/$(shell uname -r)/build
obj-m += kernel_char.o kernel_char_one.o
all:
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD)
clean:
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
这kernel_char.o
是我的 .c 文件。kernel_char_one.o
这是 .h 文件。它在输出中显示我错误地使用 .h 文件进行编译:
make -C /lib/modules/4.19.94-ti-r74/build M=/home/debian/Kernel_Modules modules
make[1]: Entering directory '/usr/src/linux-headers-4.19.94-ti-r74'
make[2]: *** No rule to make target '/home/debian/Kernel_Modules/kernel_char_one.c', needed by '/home/debian/Kernel_Modules/kernel_char_one.o'. Stop.
make[1]: *** [Makefile:1522: _module_/home/debian/Kernel_Modules] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.19.94-ti-r74'
make: *** [Makefile:9: all] Error 2
上面的输出是我使用后make
得到的Makefile
。我在想是否有某种特殊的方法可以为外部内核模块编译 .h 文件。
1. The reason for having a .h file:
a. I need my userspace program and the kernel module to know about it.