把多个源码编译成一个ko文件的方法
2016-08-23 10:30
232 查看
陆陆续续也写了几个Linux内核模块了,但每次都是把代码写在一个源文件中,上次尝试了写在两个.c文件中,结果没有编译通过。 无奈之下,将其中一个.c文件重命名成.h文件,再include当另一个当中。但是,在.h文件中写函数的实现总感觉怪怪的。 今天查看了以下Kbuild的文档,有如下描述
[c-sharp] view plaincopy
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改成如下内容:
[c-sharp] view plaincopy
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修改成如下内容:
[c-sharp] view plaincopy
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-sharp] view plaincopy
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改成如下内容:
[c-sharp] view plaincopy
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修改成如下内容:
[c-sharp] view plaincopy
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文件的方法
- Linux内核驱动将多个C文件编译成一个ko文件的方法——每一个C文件中都有module_init与module_exit
- centos主要的几个配置文件以及rpm,yum的常用命令,源码包的编译方法
- android源码环境下用mmm/mm编译模块,输出编译log到文件的方法
- Linux内核驱动将多个C文件编译成一个ko文件的方法——每个C文件里都有module_init与module_exit
- Linux内核驱动将多个C文件编译成一个ko文件的方法——每个C文件里都有module_init与module_exit,moduleinit
- Lua在 linux下源码编译问题之readline/readline.h:没有那个文件或目录解决方法
- 查找文件夹中的所有文件及子文件夹的方法,附源程序,VC7.1下编译运行通过
- 解决eclipse不编译class文件之方法
- 解决eclipse不编译class文件之方法
- 跨平台编译含中文源码方法(MSVC和GCC)
- DXperience 8.2.6注册方法(无需重新编译)、DXperience 8.2.6源码及官方下载
- Enterprise Library 3.1 May, 2007的源码的编译方法
- 引入wxWdigets的rc文件后MANIFEST编译错的解决方法
- 解决eclipse不编译class文件之方法
- linux下《UNIX环境高级编程》(apue2)源码编译出错的处理方法
- Solaris编译Boost生成so文件出错:failed gcc.link.dll解决方法
- 《UNIX环境高级编程》源码编译方法
- 用gcc编译生成动态链接库*.so文件的方法
- Java中class文件编译成exe文件的几种方法