【发布时间】:2022-01-06 23:58:12
【问题描述】:
我试图从 Linux Device Drivers 一书中做一个 hello world 模块。 但我从 gcc 收到了一个致命错误,
fatal error: linux/init.h: No such file or directory
1 | #include<linux/init.h>
我已经安装了 linux 头文件
sudo apt install linux-headers-$(uname -r)
上面写着:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
linux-headers-5.10.0-9-amd64 is already the newest version (5.10.70-1).
The following package was automatically installed and is no longer required:
libc-devtools
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
我的代码:
#include<linux/init.h>
#include<linux/module.h>
static int hello_init(void)
{
printk(KERN_ALERT,"Hello world\n");
}
static void hello_exit(void)
{
printk(KERN_ALERT,"Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
``
【问题讨论】:
-
你是怎么编译的?
-
with gcc, cc
.c -
我认为您应该使用
-I选项进行编译,然后使用标题绝对路径,该路径应位于/usr/src/ -
您需要使用适当的机制来构建它。见Building External Modules。
-
我得到了一个从tldp.org/LDP/lkmpg/2.6/html/lkmpg.html#AEN119工作的makefile