这是一个名为“Hello.c”的模块和一个“Makefile”。从工作目录执行
我尝试了所有建议,终端上显示如下内容:
make
后,会得到以下信息:
这是“Hello.c”文件:make: 没有东西要做。
#include <linux/module.h> // included for all kernel modules
#include <linux/kernel.h> // included for KERN_INFO
#include <linux/init.h> // included for __init and __exit macros
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Lakshmanan");
MODULE_DESCRIPTION("A Simple Hello World module");
static int __init hello_init(void) {
printk(KERN_INFO "Hello world!\n");
return 0; // Non-zero return means that the module couldn't be
}
static void __exit hello_cleanup(void) {
printk(KERN_INFO "Cleaning up module.\n");
}
module_init(hello_init);
module_exit(hello_cleanup);
还有“Makefile”:
obj-m += hello.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
我尝试了所有建议,终端上显示如下内容:
root@stupid-HP:/home/stupid/cpz/module$ pwd
/home/stupid/cpz/module
root@stupid-HP:/home/stupid/cpz/module$ ls
hello.c Makefile
root@stupid-HP:/home/stupid/cpz/module$ make
make: Nothing to be done for `all'.
root@stupid-HP:/home/stupid/cpz/module$ make clean
make: Nothing to be done for `clean'.
root@stupid-HP:/home/stupid/cpz/module$ make clean all
make: Nothing to be done for `clean'.
make: Nothing to be done for `all'.
root@stupid-HP:/home/stupid/cpz/module$ ls
hello.c Makefile
root@stupid-HP:/home/stupid/cpz/module$ make
make: Nothing to be done for `all'.
root@stupid-HP:/home/stupid/cpz/module$ vi hello.c # modified again
root@stupid-HP:/home/stupid/cpz/module$ make clean
make: Nothing to be done for `clean'.
root@stupid-HP:/home/stupid/cpz/module$ make
make: Nothing to be done for `all'.
hello.o
是最新的。您可以运行make clean all
,看看是否会再次收到该消息。 - BlackDwarfmake -C ...
。 - sergej