找不到linux init.h,linux/init.h: No such file or directory

问题

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

#include

#include

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

#include

#include

/* 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");

回答1:

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

#include

#include

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

回答2:

when building kernel modules you should use make files

obj-m := module_name.o

KERNELDIR ?= /lib/modules/$(shell uname -r)/build

all default: modules

install: modules_install

modules modules_install help clean:

$(MAKE) -C $(KERNELDIR) M=$(shell pwd) $@

回答3:

There's a typo in the first line of the full code "/usr/unclude..." that could be responsible for failure to find init.h

来源:https://stackoverflow.com/questions/28423477/linux-init-h-no-such-file-or-directory

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值