进入额外的目录

时间:2018-01-10 19:54:20

标签: makefile compiler-errors linux-device-driver kernel-module

我试图制作一个简单的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);

这是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

我把它们放在〜/ 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,这不是目录。关于为什么会发生这种情况以及如何解决问题的任何想法?

1 个答案:

答案 0 :(得分:0)

我明白了。它没有尝试访问一个目录,它试图访问区分大小写的Makefile,所以它必须是Makefile而不是makefile