KERN_DIR =/home/jia/linux/f1c200s/linux_kernel/linux-4.14.0+ all: make -C $(KERN_DIR) M=`pwd` modules $(CROSS_COMPILE)gcc -o led_test led_test.c clean: make -C $(KERN_DIR) M=`pwd` modules clean rm -rf modules.order rm -f led_test # leddrv.c board_demo.c 编译成 100ask.ko #100ask_led-y := leddrv.o board_demo.o obj-m += led.o
时间: 2024-04-23 12:22:35 浏览: 11
这是一个 Makefile 文件,用于编译 Linux 内核模块以及 led_test 程序。其中,KERN_DIR 变量指定了内核源码的路径,通过 make 命令和 M 参数来编译当前目录下的模块文件,最终生成 led.ko 文件。而 led_test.c 则是一个用户空间的测试程序,通过交叉编译器 $(CROSS_COMPILE)gcc 来编译生成 led_test 可执行文件。clean 目标则用于清理编译过程中生成的临时文件。
相关问题
xxx.c:8:24: fatal error: linux/init.h: No such file or directory
这个错误通常是由于缺少必要的头文件或库文件导致的。在这种情况下,错误信息指出了缺少的文件名和路径。要解决这个问题,你需要确保缺少的文件已经安装或者已经包含在你的项目中。
以下是一些可能有用的解决方法:
1. 检查文件路径是否正确。如果文件路径不正确,你需要更正路径或者将文件移动到正确的位置。
2. 确保你的编译器和构建环境已经正确地配置。如果你使用的是第三方库或工具,你需要确保它们已经正确地安装和配置。
3. 如果你使用的是第三方库,你需要确保你已经正确地链接到该库。你可以检查你的编译器选项或者Makefile文件来查看是否正确地链接到了库文件。
以下是一个可能的解决方案:
```c
#include <linux/init.h>
#include <linux/module.h>
static int __init hello_init(void)
{
printk(KERN_INFO "Hello, world!\n");
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_INFO "Goodbye, world!\n");
}
module_init(hello_init);
module_exit(hello_exit);
```
In file included from /home/lmp/000/module/hello.c:2:0: /home/lmp/000/module/hello.c: In function ‘__exittest’: /home/lmp/000/module/hello.c:14:13: error: return from incompatible pointer type [-Werror=incompatible-pointer-types] module_exit(hello_exit); ^ ./include/linux/module.h:136:11: note: in definition of macro ‘module_exit’ { return exitfn; } \ ^ cc1: some warnings being treated as errors scripts/Makefile.build:337: recipe for target '/home/lmp/000/module/hello.o' failed make[2]: *** [/home/lmp/000/module/hello.o] Error 1 Makefile:1584: recipe for target '_module_/home/lmp/000/module' failed make[1]: *** [_module_/home/lmp/000/module] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-142-generic' Makefile:4: recipe for target 'all' failed make: *** [all] Error 2
这个错误是由于`module_exit()`的使用不正确导致的。`module_exit()`函数需要一个函数指针作为参数。该函数指针指向一个函数,该函数将在卸载模块时被调用。
你的代码中使用的是一个指向`void`类型的函数指针,而实际上它需要一个指向`void __exit`类型的函数指针。
要解决这个问题,请将你的`hello_exit()`函数的返回类型更改为`void __exit`,如下所示:
```
static void __exit hello_exit(void) {
printk(KERN_INFO "Goodbye, world!\n");
}
module_exit(hello_exit);
```
这样做将把`hello_exit()`函数指定为正确的类型,并解决编译错误。