【发布时间】:2018-01-10 19:54:19
【问题描述】:
我正在尝试制作一个简单的 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("Daniel");
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 loaded.
}
static void __exit hello_cleanup(void)
{
printk(KERN_INFO "Cleaning up module.\n");
}
module_init(hello_init);
module_exit(hello_cleanup);
这是生成文件:
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
我把它们放在 ~/HelloModule 当我在那里运行 make 命令时,它给了我这个错误:
make -C /lib/modules/4.13.0-25-generic/build M=/home/dan/HelloModule modules
make[1]: Entering directory '/usr/src/linux-headers-4.13.0-25-generic'
scripts/Makefile.build:44: /home/dan/HelloModule/Makefile: No such file or directory
make[2]: *** No rule to make target '/home/dan/HelloModule/Makefile'. Stop.
Makefile:1550: recipe for target '_module_/home/dan/HelloModule' failed
make[1]: *** [_module_/home/dan/HelloModule] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.13.0-25-generic'
makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
出于某种原因,在第 4 行,make 脚本似乎正试图进入目录 /home/dan/HelloModule/Makefile,这不是目录。关于为什么会发生这种情况以及如何解决它的任何想法?
【问题讨论】:
标签: makefile compiler-errors linux-device-driver kernel-module