linux模块编译问题,急 10
程序如下:#include<liunx/init.h>#include<linux/module.h>staticinthello_init(){printk(KERN_...
程序如下:
#include <liunx/init.h>
#include <linux/module.h>
static int hello_init()
{
printk(KERN_INFO"hello world init\n");
return 0;
}
static int hello_exit()
{
printk(KERN_INFO"hello world exit\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
makefile如下:
KERN_DIR?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERN_DIR) M=$(PWD) modules -L /usr/src/linux-headers-2.6.31-14-generic/include
obj-m := hello.o
编译信息如下make -C /lib/modules/2.6.31-14-generic/build M=/work/my_work modules -L /usr/src/linux-headers-2.6.31-14-generic/include
make[1]: Entering directory `/usr/src/linux-headers-2.6.31-14-generic'
CC [M] /work/my_work/hello.o
/work/my_work/hello.c:1:24: error: liunx/init.h: No such file or directory
/work/my_work/hello.c:6: warning: function declaration isn’t a prototype
/work/my_work/hello.c:13: warning: function declaration isn’t a prototype
/work/my_work/hello.c: In function ‘hello_exit’:
/work/my_work/hello.c:15: warning: no return statement in function returning non-void
/work/my_work/hello.c: In function ‘__exittest’:
/work/my_work/hello.c:18: warning: return from incompatible pointer type
make[2]: *** [/work/my_work/hello.o] Error 1
make[1]: *** [_module_/work/my_work] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.31-14-generic
'make: *** [default] Error 2
makefile试了好几个版本就是不行,编译信息提示找不到liunx/init.h,但我搜索init是可以找到的,搜索结果如下
/usr/src/linux-headers-2.6.31-14/include/linux/init.h
设置GCC环境变量C_INCLUDE_PATH,但没有该变量 展开
#include <liunx/init.h>
#include <linux/module.h>
static int hello_init()
{
printk(KERN_INFO"hello world init\n");
return 0;
}
static int hello_exit()
{
printk(KERN_INFO"hello world exit\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
makefile如下:
KERN_DIR?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERN_DIR) M=$(PWD) modules -L /usr/src/linux-headers-2.6.31-14-generic/include
obj-m := hello.o
编译信息如下make -C /lib/modules/2.6.31-14-generic/build M=/work/my_work modules -L /usr/src/linux-headers-2.6.31-14-generic/include
make[1]: Entering directory `/usr/src/linux-headers-2.6.31-14-generic'
CC [M] /work/my_work/hello.o
/work/my_work/hello.c:1:24: error: liunx/init.h: No such file or directory
/work/my_work/hello.c:6: warning: function declaration isn’t a prototype
/work/my_work/hello.c:13: warning: function declaration isn’t a prototype
/work/my_work/hello.c: In function ‘hello_exit’:
/work/my_work/hello.c:15: warning: no return statement in function returning non-void
/work/my_work/hello.c: In function ‘__exittest’:
/work/my_work/hello.c:18: warning: return from incompatible pointer type
make[2]: *** [/work/my_work/hello.o] Error 1
make[1]: *** [_module_/work/my_work] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.31-14-generic
'make: *** [default] Error 2
makefile试了好几个版本就是不行,编译信息提示找不到liunx/init.h,但我搜索init是可以找到的,搜索结果如下
/usr/src/linux-headers-2.6.31-14/include/linux/init.h
设置GCC环境变量C_INCLUDE_PATH,但没有该变量 展开
展开全部
你的 /lib/modules/`uname -r`/build 指向哪里?
如果不存在请建立一个sym link指向你的kernel header directory:
/lib/modules/`uname -r`/build -> /usr/src/linux-headers-2.6.31-14/
Ref here:
http://www.linuxquestions.org/questions/debian-26/gcc-giving-error-linux-init-h-no-such-file-or-directory-927068/
如果不存在请建立一个sym link指向你的kernel header directory:
/lib/modules/`uname -r`/build -> /usr/src/linux-headers-2.6.31-14/
Ref here:
http://www.linuxquestions.org/questions/debian-26/gcc-giving-error-linux-init-h-no-such-file-or-directory-927068/
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询