linux 模块编译

 模板编写一个简单的Makefile,如下所示:


obj-m := hello.o


并使用如下命令编译Hello World模块,如下所示:

make -C /usr/src/linux-2.6.15.5/ M=/driver_study/ modules


如果当前处于模块所在的目录,则以下命令与上述命令同等:

make –C /usr/src/linux-2.6.15.5 M=$(pwd) modules


其中-C后指定的是Linux内核源代码的目录,而M=后指定的是hello.c和Makefile所在的目录,编译结果如下所示:

[root@localhost driver_study]# make -C /usr/src/linux-2.6.15.5/


M=/driver_study/ modules

make: Entering directory '/usr/src/linux-2.6.15.5'


CC [M] /driver_study/hello.o

/driver_study/hello.c:18:35: warning: no newline at end of file


Building modules, stage 2.

MODPOST


CC /driver_study/hello.mod.o


LD [M] /driver_study/hello.ko

make: Leaving directory '/usr/src/linux-2.6.15.5'


从中可以看出,编译过程中经历了这样的步骤:先进入Linux 内核所在的目录,并编译出hello.o 文件,运行MODPOST 会生成临时的hello.mod.c 文件,而后根据此文件编译出 hello.mod.o,之后连接hello.o 和hello.mod.o 文件得到模块 目标文件hello.ko,最后离开Linux内核所在的目录。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值