Linux Kernel Module编程,多个源文件编译成一个模块的解决方案
2010-03-11 01:51
477 查看
陆陆续续也写了几个Linux内核模块了,但每次都是把代码写在一个源文件中,上次尝试了写在两个.c文件中,结果没有编译通过。
无奈之下,将其中一个.c文件重命名成.h文件,再include当另一个当中。但是,在.h文件中写函数的实现总感觉怪怪的。
今天查看了以下Kbuild的文档,有如下描述:
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
问题解决!
无奈之下,将其中一个.c文件重命名成.h文件,再include当另一个当中。但是,在.h文件中写函数的实现总感觉怪怪的。
今天查看了以下Kbuild的文档,有如下描述:
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
问题解决!
相关文章推荐
- Linux Kernel Module编程,多个源文件编译成一个模块的解决方案
- 原已经安装好的nginx,现在需要添加一个未被编译安装的模块--echo-nginx-module-0.56
- linux 内核模块编程之编译多个源文件(三)
- 多个源文件编译成一个模块注意Makefile 书写
- linux编译多个源文件成同一个模块
- .net同一个解决方案下面多个web项目。目的为了较大项目分解模块,各自编译开发!
- 编译一个可以用Qemu进行Debug的Linux Kernel:
- IAR的一个编译错误Error[e27]: Entry "GenericApp_Init::?relay" in module Coordinator
- 根目录做了url重写,虚拟目录运行提示“未能加载文件httpmodule或它的某一个依赖项。系统找不到指定的文件”解决方案
- 1.GetModuleHandle 获取一个特定的应用程序或动态链接库的模块句柄
- Linux kernel 分析之十三:kbuild系统-编译到内核和编译成模块的区别
- 【模块化编程】理解requireJS-实现一个简单的模块加载器
- Pyhthon中使用compileall模块编译源文件为pyc文件
- Android网络编程之一个Android下菜单系统模块的实现(服务器端—更新菜单)
- [VS2010] 编译64位静态库lib提示fatal error LNK1112: module machine type 'x64' conflicts等错误的解决方案
- 编译模块出错:insmod: ERROR: could not insert module module.ko: Invalid parameters
- linux kernel 编译内核模块代码,插入内核模块遇到的问题和解决
- Android网络编程之一个Android下菜单系统模块的实现(客户端—开桌功能(上部))
- Android网络编程之一个Android下菜单系统模块的实现(服务器端—结算功能(上部))
- 编译内核驱动模块的时候错误解决方案