如何将多个源文件编译为一个.ko
2010-10-15 22:59
381 查看
陆陆续续也写了几个Linux内核模块了,但每次都是把代码写在一个源文件中,上次尝试了写在两个.c文件中,结果没有编译通过。 无奈之下,将其中一个.c文件重命名成.h文件,再include当另一个当中。但是,在.h文件中写函数的实现总感觉怪怪的。 今天查看了以下Kbuild的文档,有如下描述
整理自己的源文件成两个.c文件(simpLB.c和sahu_lb_tools.c)、一个.h文件(sahu_lb.h)和Makefile文件。两个.c文件都包含了sahu_lb.h
按照Kbuild的文档所述,把Makefile改成如下内容:
编译没有问题,但是安装后模块的功能没有实现,就连我在init_module()中打印的提示信息都没有。lsmod却有simpLB。
只好再上网查了查,发现如下文章:
http://www.linuxquestions.org/questions/programming-9/linking-multiple-files-kernel-module-programming-701735/
按照文章的的建议,我把Makefile修改成如下内容:
If a kernel module is built from several source files, you specify that you want to build a module in the same way as above. Kbuild needs to know which the parts that you want to build your module from, so you have to tell it by setting an $(<module_name>-objs) variable. Example: #drivers/isdn/i4l/Makefile obj-$(CONFIG_ISDN) += isdn.o isdn-objs := isdn_net_lib.o isdn_v110.o isdn_common.o In this example, the module name will be isdn.o. Kbuild will compile the objects listed in $(isdn-objs) and then run "$(LD) -r" on the list of these files to generate isdn.o.
整理自己的源文件成两个.c文件(simpLB.c和sahu_lb_tools.c)、一个.h文件(sahu_lb.h)和Makefile文件。两个.c文件都包含了sahu_lb.h
按照Kbuild的文档所述,把Makefile改成如下内容:
obj-m +=simpLB.o simpLB-objs:=sahu_lb_tools.o all: make -C /lib/modules/`uname -r`/build M=`pwd` clean: make -C /lib/modules/`uname -r`/build M=`pwd` clean install: /sbin/insmod simpLB.ko remove: /sbin/rmmod simpLB
编译没有问题,但是安装后模块的功能没有实现,就连我在init_module()中打印的提示信息都没有。lsmod却有simpLB。
只好再上网查了查,发现如下文章:
http://www.linuxquestions.org/questions/programming-9/linking-multiple-files-kernel-module-programming-701735/
按照文章的的建议,我把Makefile修改成如下内容:
obj-m +=sahuLB.o sahuLB-objs:=simpLB.o sahu_lb_tools.o all: make -C /lib/modules/`uname -r`/build M=`pwd` clean: make -C /lib/modules/`uname -r`/build M=`pwd` clean install: /sbin/insmod sahuLB.ko remove: /sbin/rmmod sahuLB
相关文章推荐
- 如何将多个源文件编译为一个.ko
- 如何将多个源文件编译为一个.ko
- 将多个源文件编译成一个ko
- 如何编译内核中某一个ko模块(1)
- (转)如何手动编译一个APK
- android编译时如何决定一个APK等Module是否被自动编译到system.img中
- 如何编译一个内核 - Ubuntu方式
- 如何编写并编译一个shellcode(linux)
- 如何编译和加载.ko模块
- 如何用一个makefile编译多个目标
- Linux中编译一个简单的源文件的过程
- Linux Kernel Module编程,多个源文件编译成一个模块的解决方案
- C语言一个源文件如何调用另一个源文件里的函数
- 如何编译一个精简的Android系统
- 编译运行symbian程序(如何打开一个symbian工程)
- 如何用程序执行一个项目的编译?
- Linux Kernel Module编程,多个源文件编译成一个模块的解决方案
- 46.如何创建、编译和执行同一个包内的多个文件
- 如何编译一个内核 - Ubuntu方式
- 如何编译一个内核 - Ubuntu方式