linux 为什么编译为模块,linux模块编译异常

hello.c:

#include

#include

#include

static int hello_init(void){

printk(KERN_ALERT "hello worldn");

return 0;

}

static void hello_exit(void){

printk(KERN_ALERT "goodbye worldn");

}

module_init(hello_init);

modlue_exit(hello_exit);

MODLUE_LICENSE("GPL");

MOULUE_AUTHOR("xuhui");

MODLUE_DESCRIPTION("my frist driver,is hello");

MODULE_VERSION("1.0");

Makefile:

obj-m := modules_hello.o

modules_hello-objs := hello.o

KDIR := /lib/modules/$(shell uname -r)/build

PWD := $(shell pwd)

default:

make -C $(KDIR) M=$(PWD) modules

clean:

rm -rf *.o .* .cmd *.KO *.mod.c .tmp_versions

终端运行结果:

[root@bogon ~]# cd /hello/

[root@bogon hello]# ls

hello.c  Makefile

[root@bogon hello]# make

make -C /lib/modules/2.6.23.1-42.fc8/build M=/hello modules

make[1]: Entering directory `/usr/src/kernels/2.6.23.1-42.fc8-i686'

CC [M]  /hello/hello.o

/hello/hello.c:15: 警告:数据定义时没有类型或存储类

/hello/hello.c:15: 警告:在 ‘modlue_exit’ 的声明中,类型默认为 ‘int’

/hello/hello.c:15: 警告:函数声明中出现形参名却未指定类型

/hello/hello.c:17: 错误:expected declaration specifiers or ‘...’ before string constant

/hello/hello.c:17: 警告:数据定义时没有类型或存储类

/hello/hello.c:17: 警告:在 ‘MODLUE_LICENSE’ 的声明中,类型默认为 ‘int’

/hello/hello.c:17: 警告:函数声明不是一个原型

/hello/hello.c:18: 错误:expected declaration specifiers or ‘...’ before string constant

/hello/hello.c:18: 警告:数据定义时没有类型或存储类

/hello/hello.c:18: 警告:在 ‘MOULUE_AUTHOR’ 的声明中,类型默认为 ‘int’

/hello/hello.c:18: 警告:函数声明不是一个原型

/hello/hello.c:19: 错误:expected declaration specifiers or ‘...’ before string constant

/hello/hello.c:19: 警告:数据定义时没有类型或存储类

/hello/hello.c:19: 警告:在 ‘MODLUE_DESCRIPTION’ 的声明中,类型默认为 ‘int’

/hello/hello.c:19: 警告:函数声明不是一个原型

make[2]: *** [/hello/hello.o] 错误 1

make[1]: *** [_module_/hello] 错误 2

make[1]: Leaving directory `/usr/src/kernels/2.6.23.1-42.fc8-i686'

make: *** [default] 错误 2

[root@bogon hello]#

这是我才开始接触liunx,学着编译模块。

请问这个Makefile究竟哪里有错啊?

编译时总是报这样的异常。在Redhat下和Ubuntu下都报这样的错。

|

static int hello_init(void){

改为

static int __init hello_init(void){

static void hello_exit(void){

改为

static void __exit hello_exit(void){

|

是的,学习了。误导LZ,抱歉啊。

|

楼主下载了内核头了吗?

感觉2.6.23.1-42.fc8-i686是系统默认的,可能没有内核头。

可以去kernel.org下一个内核源代码。

内核头英文好像是kernel-headers。

另外,也可以看看一些经典的书,LDD3,或者其它XXX驱动设计入门之类的书。

如不正确,希望指正。

|

缺少头文件。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值