当前位置: 技术问答>linux和unix
谁用这种方法编译成功过模块的?
来源: 互联网 发布时间:2015-06-24
本文导语: The reliable, future-proof, way to build external modules is to leverage the ker nel's build system to do the hard work for you. Use autoconf or a similar mechan ism to discover the kernel source tree (defaulting to the /lib/modules/`uname -r...
The reliable, future-proof, way to build external modules is to leverage the ker
nel's build system to do the hard work for you. Use autoconf or a similar mechan
ism to discover the kernel source tree (defaulting to the /lib/modules/`uname -r
`/build/include path). Read Documentation/kbuild/ to find out what your Makefile
should look like for the module build itself, and then arrange to call make fro
m the kernel base dir, setting SUBDIRS as necessary. For example, if your genera
ted Makefile is in /home/luser/src/mymodule-0.1/module/, and the user's kernel s
ource tree is /usr/src/linux-2.5, then the makefile fragment might look like :
kernel_module:
$(MAKE) -C /usr/src/linux-2.5 SUBDIRS=/home/luser/src/mymodule-0.1/module/ mo
dules
This will set all the flags you need correctly in a future-proof fashion by usin
g the kernel build machinery itself to generate the module. You can find a very
simple example for 2.6 kernels here : sillymod.tar.gz. It builds with the standa
rd "./configure; make; make install"
在http://www.kernelnewbies.org/faq/上看到这个方法,但是了一下除了一些问题,不知
道有没人用过。
帮帮忙研究一下。
nel's build system to do the hard work for you. Use autoconf or a similar mechan
ism to discover the kernel source tree (defaulting to the /lib/modules/`uname -r
`/build/include path). Read Documentation/kbuild/ to find out what your Makefile
should look like for the module build itself, and then arrange to call make fro
m the kernel base dir, setting SUBDIRS as necessary. For example, if your genera
ted Makefile is in /home/luser/src/mymodule-0.1/module/, and the user's kernel s
ource tree is /usr/src/linux-2.5, then the makefile fragment might look like :
kernel_module:
$(MAKE) -C /usr/src/linux-2.5 SUBDIRS=/home/luser/src/mymodule-0.1/module/ mo
dules
This will set all the flags you need correctly in a future-proof fashion by usin
g the kernel build machinery itself to generate the module. You can find a very
simple example for 2.6 kernels here : sillymod.tar.gz. It builds with the standa
rd "./configure; make; make install"
在http://www.kernelnewbies.org/faq/上看到这个方法,但是了一下除了一些问题,不知
道有没人用过。
帮帮忙研究一下。
|
呵呵,偶一般直接用gcc命令。
|
这是Linux-2.5.x和2.6.x的kbuild机制,在这种环境下,module的生成方法与Linux-2.4.x下有很大的区别。