C语言 为什么 make 打印 "make: nothing to do for `all'."?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32903139/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 12:09:40  来源:igfitidea点击:

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

cmakefilelinux-kernellinux-device-drivergnu-make

提问by user55111

This is a "Hello.c" module and "Makefile". After executing makefrom the woking directory I get the following message:

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

make: Nothing to be done for `all'.

make:对“所有人”无事可做。

This is the "Hello.c" file:

这是“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);

And "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

I tried all suggestions and I got this in the terminal:

我尝试了所有建议,并在终端中得到了这个:

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'.

采纳答案by incompetent

Make works on the base of time stamps. If you alter some of your source files Make compile them and built the image accordingly. If you do not change source file then compiler has nothing to do with your project. make does not work like gccto compile every time whether new build is needed or not. This is one of many advantages of using make for your project.

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

回答by Dilip Kumar

  1. make cleanand then makeagain
  2. check for spaces and tabs as per make file format
  3. Verify the Path of the kernel libraries
  1. make clean然后make
  2. 根据 make 文件格式检查空格和制表符
  3. 验证内核库的路径

回答by Hoang Pham

You should remove space in your Makefile. In makefile, only use tab.

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

I tested your code again, and it works with tab

我再次测试了您的代码,它适用于选项卡

回答by LPs

Compiler is simply telling you that your code was already compiled and there are no changes in your code (it is up to date), then it does not compile. Is a builtin feature of compilers, if there are no changes in source code file, compilers do not waste time.

编译器只是告诉您您的代码已经编译并且您的代码没有更改(它是最新的),然后它不会编译。是编译器的内置功能,如果源代码文件没有变化,编译器不会浪费时间。

Use make cleanbefore to makeor modify Hello.cand Build your project.

使用make cleanbeforemake或修改Hello.c和构建您的项目。

回答by sofronas

Try : make clean to delete the executable file (./a.out) and try to compile it again! You may have something change in some fuction and make can't see it

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

回答by idclev 463035818

Just in case someone encounters the same problem as me:

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

Eclipse fails to build correctly when one of your folders has the same name as the executable. If this is the case, no matter what you do, you will always get the "nothing to be done" message. The solution is to rename either the folder or executable. Details can be found here.

当您的文件夹之一与可执行文件同名时,Eclipse 无法正确构建。如果是这种情况,无论您做什么,您总是会收到“无事可做”的消息。解决方案是重命名文件夹或可执行文件。可在此处找到详细信息。