Linux make: 没有规则来制作目标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19347448/
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
make: no rule to make target
提问by Pushkar Dhande
i have written a simple linux module & its make file
我写了一个简单的 linux 模块及其 make 文件
this is my module
这是我的模块
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void) {
printk("<1> Hello world!\n");
return 0;
}
static void hello_exit(void) {
printk("<1> Bye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
this is my make file
这是我的make文件
obj-m :=Hello.o
KDIR = /usr/src/linux-headers-3.5.0-17
all:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
rm -rf *.o *.ko *.mod.* *.symvers *.order
when i execute make -f MakeFile it gives following o/p
当我执行 make -f MakeFile 它给出以下 o/p
make -C /usr/src/linux-headers-3.5.0-17 SUBDIRS=/home/linux/Desktop modules
make[1]: Entering directory `/usr/src/linux-headers-3.5.0-17'
WARNING: Symbol version dump /usr/src/linux-headers-3.5.0-17/Module.symvers
is missing; modules will have no dependencies and modversions.
scripts/Makefile.build:44: /home/linux/Desktop/Makefile: No such file or directory
make[2]: *** No rule to make target `/home/linux/Desktop/Makefile'. Stop.
make[1]: *** [_module_/home/linux/Desktop] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.5.0-17'
make: *** [all] Error 2
can any one tell me how to get rid of these errors. Thanks in advance
谁能告诉我如何摆脱这些错误。提前致谢
回答by vinay hunachyal
Make the below change in your Makefile
在您的 Makefile 中进行以下更改
First check which kernel is running by typing uname -a
首先通过键入 uname -a 检查哪个内核正在运行
Then go to cd /usr/src/
然后转到 cd /usr/src/
then check your linux source-code name
然后检查你的 linux 源代码名称
for e.g
例如
uname -a Linux vinay-VirtualBox 3.2.0-50-generic-pae #76-Ubuntu SMP Tue Jul 9 19:24:55 UTC 2013 i686 i686 i386 GNU/Linux
uname -a Linux vinay-VirtualBox 3.2.0-50-generic-pae #76-Ubuntu SMP Tue Jul 9 19:24:55 UTC 2013 i686 i686 i386 GNU/Linux
here its source-code name is linux-headers-3.2.0-50-generic-pae same thing in your case e.g
这里它的源代码名称是 linux-headers-3.2.0-50-generic-pae 在你的情况下同样的事情,例如
linux-headers-3.2.0-23 linux-headers-3.2.0-23-generic-pae
so use linux-headers-3.2.0-23-generic-pae
instead of
linux-headers-3.2.0-23 i.e replace same in your makefile
linux-headers-3.2.0-23 linux-headers-3.2.0-23-generic-pae 所以使用linux-headers-3.2.0-23-generic-pae
而不是 linux-headers-3.2.0-23 即在你的makefile中替换相同的
i.e KDIR=/usr/src/linux-headers-3.5.0-17-generic-pae
即 KDIR=/usr/src/linux-headers-3.5.0-17-generic-pae
or in order to avoid above problem useKDIR == /lib/modules/$(shell uname -r)/build
或为了避免上述问题使用KDIR == /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
KDIR == /lib/modules/$(shell uname -r)/build
$(MAKE) -C $(KDIR) M=$(PWD) modules
回答by DreamCoder
obj-m += xyz.o
KDIR:=/usr/src/linux-headers-3.5.0-46-generic
all:
make -C $(KDIR) M=$(PWD) modules
clean:
make -C $(KDIR) M=$(PWD) clean
Are you sure /usr/src/
contains linux-headers-3.5.0-46-generic files?
if this is not the case, download:
您确定/usr/src/
包含 linux-headers-3.5.0-46-generic 文件吗?如果不是这种情况,请下载:
sudo apt-get install linux-headers-3.5.0-46
sudo apt-get install linux-headers-3.5.0-46-generic