【发布时间】:2015-10-02 08:19:17
【问题描述】:
这是一个“Hello.c”模块和“Makefile”。从 woking 目录执行 make 后,我收到以下消息:
make: `all' 无事可做。
这是“Hello.c”文件:
#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'.
【问题讨论】:
-
我检查了,当前工作目录中没有其他 makefile。只有两个文件 hello.c 和 makefile。 (谢谢回复)
-
如果你的程序被编译,编译器不会被调用。您必须修改源文件或删除编译器输出才能立即运行编译器。这是基于时间戳的。
-
这可能只是意味着
hello.o是最新的。您可以运行make clean all并查看是否再次收到该消息。 -
确保
make -C ...用TAB(不是空格)缩进 -
@sergej 谢谢......正如你所说,我删除了 Makefile 中的空格并用 TAB 替换。现在它的工作和我能够使用 insmod 。
标签: c makefile linux-kernel linux-device-driver gnu-make