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

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

问题描述

我正在尝试为我的一个类建立一个内核模块,并且我遇到了一个错误,但在墙壁的顶部是臭名昭着的没有这样的文件或目录的错误。这似乎是问题的根源。这不仅似乎影响了init.h,还影响了module.h和kernel.h。程序的前三行如下:

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

我浏览了周围,并尝试了其他路径,这些文件在浏览类似问题时应该是这样的,但迄今没有任何工作。最奇怪的是我已经使用这个模块了我被提供了启动器代码,这在顶部(我没有改变任何东西),它没有给我这个错误。虽然,显然后面的代码是不同的,但这似乎是目前最大的问题。



完整的代码如下:

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

/ *加载模块时调用此函数。 * /
int simple_init(void)
{
printk(KERN_INFOLoading Module\\\
);
static LIST_HEAD(birthday_list)
struct birthday {
int day;
int month;
int year;
struct list_head列表;
};
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 - >天= 17;
bob - >月= 1;
bob - >年= 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 \\\
',ptr - > month,ptr - 日,ptr - >年);
}



list_for_each_entry_safe(ptr,& birthday_list,list){

list_del(& ptr-> list) ;
kfree(ptr);
}

返回0;
}

/ *当该模块被删除时,此函数被调用。 * /
void simple_exit(void){
printk(KERN_INFORemove Module\\\
);
}

/ *用于注册模块入口和出口点的宏。 * /
module_init(simple_init);
module_exit(simple_exit);

MODULE_LICENSE(GPL);
MODULE_DESCRIPTION(简单模块);
MODULE_AUTHOR(SGG);


解决方案

我想你必须先安装像linux-headers - [内核版本]由apt-get然后您必须创建Makefile如下:

  ifneq($(KERNELRELEASE),)
#从内核构建系统调用
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)/../包括模块
$(MAKE)-C $(KERNELDIR)M = $(PWD)LDDINC = $(PWD)/../包含模块
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,$(通配符.depend))
包含.depend
endif

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

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

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


I'm trying to build a kernel module for a class of mine and I'm getting a 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.

The full code is as follows:

#include <usr/unclude/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");

解决方案

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

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>

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天全站免登陆