linux/init.h:没有这样的文件或目录 [英] linux/init.h: No such file or directory

查看:339
本文介绍了linux/init.h:没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的班级构建一个内核模块,并且遇到了很多错误,但是最臭名昭著的是没有这样的文件或目录"错误.这似乎是问题的根源.这似乎不仅会影响init.h,而且还会影响module.h和kernel.h.该程序的前三行如下:

I'm trying to build a kernel module for my class, and I'm getting a massive wall of errors, but at the top of said wall is the infamous 'No such file or directory' error. It seems to be the root of the problem. This not only seems to affect init.h, but also module.h and kernel.h. The first three lines of the program go as follows:

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>

在浏览类似问题时,我环顾四周并尝试了其他路径来确定这些文件的位置,但到目前为止没有任何效果.最奇怪的部分是我已经使用了这个模块.提供给我的启动器代码顶部是该代码(我没有做任何更改),并且没有给我该错误.虽然,显然之后的代码不同,但这似乎是当前最大的问题.

I've looked around and tried other paths for where these files ought to be when browsing similar issues, but nothing has worked thus far. The strangest part is that I used this module already; I was provided starter code that had this at the top (I didn't change anything) and it didn't give me that error. Although, obviously the code after is different, but this seems to be the biggest problem at the moment.

完整代码如下:

#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");

推荐答案

我认为您必须先通过apt-get安装类似linux-headers- [kernel version]之类的东西,然后才能创建Makefile,如下所示:

I think you must first install something like linux-headers-[kernel version] by apt-get then you must create Makefile as following :

ifneq ($(KERNELRELEASE),)
    # call from kernel build system
    lifo-objs := main.o
    obj-m   := lifo.o
else
   KERNELDIR ?= /lib/modules/$(shell uname -r)/build
   PWD       := $(shell pwd)
modules:
    echo $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
    $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
endif

clean:  
    rm -rf *.o *~ core .depend *.mod.o .*.cmd *.ko *.mod.c \
    .tmp_versions *.markers *.symvers modules.order

depend .depend dep:
    $(CC) $(CFLAGS) -M *.c > .depend

ifeq (.depend,$(wildcard .depend))
    include .depend
endif

在Makefile中将KERNELDIR变量设置为您合适的内核版本,默认情况下它使用您正在运行的内核.如果您使用此Makefile,则需要将包含内容更改为以下格式:

set KERNELDIR variable in above Makefile to your appropriate kernel version, by default it use your running kernel. If you use this Makefile you need to change your include to following format:

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>

对于内核模块开发,我认为使用 Linus Torvalds git 的标准内核更好.有关一些简单的内核模块,请参见.

I think for kernel module developing use standard kernel from Linus Torvalds git is better. For some simple kernel module see this.

这篇关于linux/init.h:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆