我正在遵循Linux内核模块编程指南的hello world编程示例(第8-9页):https://tldp.org/LDP/lkmpg/2.6/lkmpg.pdf
我有如下的hello-1.c,如指南中所述:
/*
* hello−1.c − The simplest kernel module.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
int init_module(void) {
printk(KERN_INFO "Hello world 1.\n");
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}
void cleanup_module(void) {
printk(KERN_INFO "Goodbye world 1.\n");
}以及第9页上的Makefile:
obj−m += hello−1.o
all:
sudo make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean当我将Makefile与make一起使用时,我得到了以下输出:
make -C /lib/modules/5.4.0-60-generic/build M=/home/joeyoneill/Desktop/CSCI614 modules
make[1]: Entering directory '/usr/src/linux-headers-5.4.0-60-generic'
Building modules, stage 2.
MODPOST 0 modules
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-60-generic'制作了2个文件(Module.symvers和modules.order)。
然而,我不明白:
hostname:~/lkmpg−examples/02−HelloWorld# make
make −C /lib/modules/2.6.11/build M=/root/lkmpg−examples/02−HelloWorld modules
make[1]: Entering directory `/usr/src/linux−2.6.11'
CC [M] /root/lkmpg−examples/02−HelloWorld/hello−1.o
Building modules, stage 2.
MODPOST
CC /root/lkmpg−examples/02−HelloWorld/hello−1.mod.o
LD [M] /root/lkmpg−examples/02−HelloWorld/hello−1.ko
make[1]: Leaving directory `/usr/src/linux−2.6.11'
hostname:~/lkmpg−examples/02−HelloWorld#这是书中给出的输出,所以我没有创建这个.o或.ko文件。如下图所示:
CC /root/lkmpg−examples/02−HelloWorld/hello−1.mod.o
LD [M] /root/lkmpg−examples/02−HelloWorld/hello−1.ko有人能告诉我我哪里做错了吗?
发布于 2021-08-07 17:38:11
Linux Kernel Module Programming Guide现在针对v5.x内核进行了维护,您可以获得该书以及工作示例:https://github.com/sysprog21/lkmpg
https://stackoverflow.com/questions/65877692
复制相似问题