为什么 make printing "make: Nothing to be done for `all'."?

Why is make printing "make: Nothing to be done for `all'."?

这是一个 "Hello.c" 模块和 "Makefile"。从 woking 目录执行 make 后,我收到以下消息:

make: Nothing to be done for `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'.

编译器只是简单地告诉你你的代码已经被编译并且你的代码没有任何变化(它是最新的),那么它就不会编译。是编译器的内建特性,如果源代码文件没有变化,编译器不会浪费时间。

make 之前使用 make clean 或修改 Hello.c 并构建您的项目。

根据时间戳制作作品。如果您更改了一些源文件,请编译它们并相应地构建图像。如果您不更改源文件,那么编译器与您的项目无关。无论是否需要新构建,make 都不像 gcc 那样每次都编译。这是为您的项目使用 make 的众多优势之一。

  1. make clean 然后 make 再次
  2. 根据 make 文件格式检查空格和制表符
  3. 验证内核库的路径

尝试 : make clean 删除可执行文件 (./a.out) 并尝试重新编译! 您可能在某些功能上发生了一些变化并且看不到它

万一有人遇到和我一样的问题:

当您的文件夹之一与可执行文件同名时,Eclipse 无法正确构建。如果是这种情况,无论您做什么,您将始终收到 "nothing to be done" 消息。解决方案是重命名文件夹或可执行文件。详情可见here.

您应该删除 Makefile 中的 space。在 makefile 中,只使用 tab.

我再次测试了您的代码,它可以与选项卡一起使用