编译内核模块,头的问题,问题的makefile [英] Compiling a kernel module, header problems, makefile problems

查看:325
本文介绍了编译内核模块,头的问题,问题的makefile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定我想要编译一个简单的内核模块,当我指向任何含有包括下面的,它抱怨各种东西。

  Linux的头-2.6.31-21 Linux的头-2.6.31-22
Linux的头-2.6.31-21-通用Linux-头-2.6.31-22泛型
Linux的头-2.6.31-21-仿制PAE Linux的头-2.6.31-22-仿制PAE

我试图遵循以下站点上的说明:
http://www.faqs.org/docs/kernel/x145.html

我更新了make文件看起来是这样的:

 目标:=参考hello world
警告:= -W -Wall -Wstrict的原型-Wmissing的原型
包含:= -isystem /usr/src/linux-headers-2.6.31-22-generic/include
CFLAGS:= -O2 -DMODULE -D__KERNEL__ $ {WARN} $ {} INCLUDE
CC:= GCC$ {}目标的.o:$ {TARGET} .C.PHONY:干净清洁:
    室射频$ {}目标的.o

例如,当我在制式我碰到下面的错误,以及更多的人,调查我看到处理器和缓存文件都在ASM-通用文件夹,如何在世界上我应该编译这个如果是在文件的正确的位置没有指向?

  /usr/src/linux-headers-2.6.31-22-generic/include/linux/$p$pfetch.h:14:27:错误:ASM /处理器。 H:没有这样的文件或目录
/usr/src/linux-headers-2.6.31-22-generic/include/linux/$p$pfetch.h:15:23:错误:ASM / cache.h:没有这样的文件或目录

终极目标(吓人)正在建设一个虚拟文件系统,周四... ...(是啊,我知道这是pretty不太可能)
我了解一些make文件,但奇怪的是我的预期,我应该看到类似$ {CC} $ {} INCLUDE,像这样的事情,但我没有看到,在所有的,

有人能解释和/所有的以下几个问题?


  1. 什么我需要更新包括,所以它知道正确的目录(如果它的东西就像我使用的是什么内核等,请解释一下我怎么可以算出来)。


  2. 有人能解释的makefile如何知道调用gcc和编译?


  3. 还有什么我需要知道让这件事来编译?


- 奖金问题


  1. 任何人都知道如何建立一个VFS任何真正详细的教程,我有一个项目,我们被分配了另一所学校做了,的 http://oslab.info/index.php/Labs/HW4 ,并根据有限的编程,我们在此之前所做的,它看似是一项艰巨的任务。


解决方案

使用2.6内核,你应该使用内核构建系统。下面是内核树之外建立一个模块的例子:

  ifneq($(KERNELRELEASE))
#我们被称为kbuild的物镜-M + = target.o别的#我们在命令行中被称为KDIR:= / lib / modules目录/ $(壳使用uname -r)/建
#KDIR:= /home/cynove/src/kernel/linux-source-2.6.31
PWD:= $(壳PWD)默认:
    @echo建设目标模块2.6版本的内核。
    @echo请忽略重写SUBDIRS警告
    $(MAKE)-C $(KDIR)SUBDIRS = $(PWD)模块安装:
    ./do_install.sh * .koENDIF#结束的kbuild检查
#########################版本独立目标###################### ####清洁:
    RM -f -r * *的.o .ko。* CMD的.tmp * *核心.I

通过调用使-C($ KDIR)等等,内核构建系统介入,并做这项工作适合你。

ok I'm trying to compile a simple kernel module, when I point to any of the below that contain includes, it complains about all kinds of stuff.

linux-headers-2.6.31-21              linux-headers-2.6.31-22              
linux-headers-2.6.31-21-generic      linux-headers-2.6.31-22-generic      
linux-headers-2.6.31-21-generic-pae  linux-headers-2.6.31-22-generic-pae

I'm attempting to follow the instructions on the following site: http://www.faqs.org/docs/kernel/x145.html

I updated the make file to look like this:

TARGET  := hello_world
WARN    := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /usr/src/linux-headers-2.6.31-22-generic/include
CFLAGS  := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC      := gcc

${TARGET}.o: ${TARGET}.c

.PHONY: clean

clean:
    rm -rf ${TARGET}.o

for example when I type in make I get the following error as well as many more, investigating the folders I see that the processor and cache files are in asm-generic, how in the world am I supposed to compile this if it's not pointing at the right locations of the files?

/usr/src/linux-headers-2.6.31-22-generic/include/linux/prefetch.h:14:27: error: asm/processor.h: No such file or directory
/usr/src/linux-headers-2.6.31-22-generic/include/linux/prefetch.h:15:23: error: asm/cache.h: No such file or directory

The ultimate goal (scary) is building a virtual file system, by thursday....(yea I know it's pretty unlikely) I understand some of the make file, but oddly enough I expected that I should see something like ${CC} ${INCLUDE}, things like this, but I don't see that at all,

Can someone explain and/all of the following questions?

  1. What do I need to update my include to so it knows the right directory (and if it's something like what kernel I'm using etc, please explain how I can figure this out).

  2. Can someone explain how the makefile knows to call gcc and compile?

  3. Is there anything else I need to know to get this thing to compile?

-- Bonus question

  1. Anyone know any REALLY detailed tutorials about how to build a VFS, I have a project we were assigned that another school did, http://oslab.info/index.php/Labs/HW4, and based on the limited programming we've done before this, it is appearing to be a monumental task.

解决方案

With 2.6 kernel, you should use the kernel build system. Here is an example for a module built outside of the kernel tree :

ifneq ($(KERNELRELEASE),)
# We were called by kbuild

obj-m += target.o

else  # We were called from command line

KDIR := /lib/modules/$(shell uname -r)/build
#KDIR := /home/cynove/src/kernel/linux-source-2.6.31
PWD  := $(shell pwd)

default:
    @echo '    Building target module 2.6 kernel.'
    @echo '    PLEASE IGNORE THE "Overriding SUBDIRS" WARNING'
    $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

install:
    ./do_install.sh *.ko

endif  # End kbuild check
######################### Version independent targets ##########################

clean:
    rm -f -r *.o *.ko .*cmd .tmp* core *.i

By calling make -C ($KDIR) etc..., the kernel build system gets involved, and does the job for you.

这篇关于编译内核模块,头的问题,问题的makefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆