【发布时间】:2015-04-10 00:02:21
【问题描述】:
我正在尝试为我的班级构建一个内核模块,但我遇到了一大堵错误墙,但在所述墙的顶部是臭名昭著的“没有这样的文件或目录”错误。这似乎是问题的根源。这似乎不仅会影响 init.h,还会影响 module.h 和 kernel.h。程序的前三行如下:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
在浏览类似问题时,我环顾四周并尝试了这些文件应该在哪里的其他路径,但到目前为止没有任何效果。最奇怪的是我已经用过这个模块了;我得到了顶部有这个的起始代码(我没有改变任何东西)并且它没有给我那个错误。虽然,显然后面的代码不同,但这似乎是目前最大的问题。
完整代码如下:
#include </usr/include/linux/init.h>
#include </usr/include/linux/module.h>
#include </usr/include/linux/kernel.h>
/* This function is called when the module is loaded. */
int simple_init(void)
{
printk(KERN_INFO "Loading Module\n");
static LIST_HEAD(birthday_list)
struct birthday{
int day;
int month;
int year;
struct list_head list;
};
struct birthday *ptr, *next;
struct birthday *bob;
struct birthday *judy;
struct birthday *josh;
struct birthday *lana;
struct birthday *jan;
bob = kmalloc(sizeof(*bob), GFP_KERNEL);
bob -> day = 17;
bob -> month = 1;
bob -> year = 1990;
INIT_LIST_HEAD(&bob -> list);
...
list_add_tail(bob -> list, &birthday_list);
list_add_tail(judy -> list, &birthday_list);
list_add_tail(josh -> list, &birthday_list);
list_add_tail(lana -> list, &birthday_list);
list_add_tail(jan -> list, &birthday_list);
struct birthday *ptr;
list_for_each_entry(ptr, &birthday_list, list){
kprintf('%d/%d/%d \n', ptr -> month, ptr -> day, ptr -> year);
}
list_for_each_entry_safe(ptr, &birthday_list, list){
list_del(&ptr->list);
kfree(ptr);
}
return 0;
}
/* This function is called when the module is removed. */
void simple_exit(void) {
printk(KERN_INFO "Removing Module\n");
}
/* Macros for registering module entry and exit points. */
module_init( simple_init );
module_exit( simple_exit );
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Simple Module");
MODULE_AUTHOR("SGG");
【问题讨论】:
-
你的
init.h副本在哪里,你传递给gcc的包含路径是什么? -
你能发布你的代码吗?你在使用 /lib/module 中提供的 Makefile 吗?
-
好吧,我有几件事要报告。一方面,init.h 和 module.h 似乎消失了。此外,我试图解决这个问题,但事情......不知何故出了问题。我尝试使用命令“sudo apt-get install linux-headers-generic”,它给了我一条错误消息:“E: Package 'linux-headers-generic' has no installation Candidate.”
-
我没有使用您所说的 Makefile,但我尝试运行的模块目录中有一个。至于发布代码,中间有很多填充物,这并不重要……我会努力把它发布;我让它在虚拟机上运行。
标签: c linux module kernel debian