当前位置: 技术问答>linux和unix
编译模块问题,最基础的那种
来源: 互联网 发布时间:2016-03-18
本文导语: Linux2.6写的模块a.c: #include #include #include MODULE_LICENSE("GPL"); static int hello_init(void) { printk("Hello, World!n"); return 0; } static void hello_exit(void) { printk("Goodbye, Cruel World!n"); return; } module_init...
Linux2.6写的模块a.c:
#include
#include
#include
MODULE_LICENSE("GPL");
static int hello_init(void)
{
printk("Hello, World!n");
return 0;
}
static void hello_exit(void)
{
printk("Goodbye, Cruel World!n");
return;
}
module_init(hello_init);
module_exit(hello_exit);
编译后报错:
a.c:1:24: error: linux/init.h: 没有那个文件或目录
a.c:3:26: error: linux/module.h: 没有那个文件或目录
a.c:5: error: expected declaration specifiers or ‘...’ before string constant
a.c:5: warning: data definition has no type or storage class
a.c:19: warning: data definition has no type or storage class
a.c:19: warning: parameter names (without types) in function declaration
a.c:20: warning: data definition has no type or storage class
a.c:20: warning: parameter names (without types) in function declaration
make: *** [a] 错误 1
大家帮帮忙?
#include
#include
#include
MODULE_LICENSE("GPL");
static int hello_init(void)
{
printk("Hello, World!n");
return 0;
}
static void hello_exit(void)
{
printk("Goodbye, Cruel World!n");
return;
}
module_init(hello_init);
module_exit(hello_exit);
编译后报错:
a.c:1:24: error: linux/init.h: 没有那个文件或目录
a.c:3:26: error: linux/module.h: 没有那个文件或目录
a.c:5: error: expected declaration specifiers or ‘...’ before string constant
a.c:5: warning: data definition has no type or storage class
a.c:19: warning: data definition has no type or storage class
a.c:19: warning: parameter names (without types) in function declaration
a.c:20: warning: data definition has no type or storage class
a.c:20: warning: parameter names (without types) in function declaration
make: *** [a] 错误 1
大家帮帮忙?
|
1、这个代码没有问题,用这个makefile应该OK
#Makefile
obj-m:=hello.o
KERNELDIR ?=/usr/src/kernel-2.6.xx(这个路径视你的内核代码目录而定)
PWD:=$(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
2、这个代码应该还用不到linux/kernel.h
#Makefile
obj-m:=hello.o
KERNELDIR ?=/usr/src/kernel-2.6.xx(这个路径视你的内核代码目录而定)
PWD:=$(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
2、这个代码应该还用不到linux/kernel.h
|
把你的 makefile贴出来. 另外可以去看看.
http://blog.csdn.net/pottichu/archive/2007/11/19/1892245.aspx
http://blog.csdn.net/pottichu/archive/2007/11/19/1892245.aspx