在Linux中编译内核模块时遇到麻烦 [英] trouble compiling a kernel module in linux
问题描述
我写了一个简单的hello world内核模块.我写了一个make文件,如下所示:
I wrote a simple hello world kernel module. A make file was written by me as below:
obj -m += hello.o
KDIR: /usr/src/linux-headers-3.2.0-21-generic-pae
all:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
rm -rf *.o *.ko *.mod.* *.symvers *.order
然后我使用make编译了模块.它工作得很好.
Then I compiled the module using make. It worked just fine.
然后,最近,当内核更新为3.2.0-24时,我再次执行了"make"操作(当然,我在KDIR中将版本更改为24).但是出现了以下错误:
Then, recently I did 'make' again when the kernel was updated to 3.2.0-24(of course I changed the version to 24 in KDIR). But the following error cropped up:
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-24-generic-pae'
make[2]: *** No rule to make target `arch/x86/tools/relocs.c', needed
by `arch/x86/tools/relocs'. Stop.
我检查并发现/arch/x86/tools/中存在relocs的可执行文件,但没有relocs.c
I checked and found that an executable file of relocs was there at /arch/x86/tools/ but there was no relocs.c
出了什么问题,如何纠正它才能成功编译模块?
What went wrong and how should I correct it so that I successfully compile the module?
推荐答案
请共享您编写的hello-world模块代码.
Pls share the hello-world module code that you have written.
relocs.c位于内核src内的arch/x86/tools下.
relocs.c is present under arch/x86/tools inside the kernel src.
由于您的计算机上仅安装了linux-header,因此可能看不到relocs.c文件. 您必须下载整个内核src.
As you have only linux-headers installed on your machine you may not see relocs.c file. You have to download the entire kernel src.
请按照以下步骤操作:
$ sudo apt-get更新
$ sudo apt-get update
$ sudo apt-get install linux-source.
$ sudo apt-get install linux-source.
作为一个试验(下载内核src之后),您可以更改makefile以将KDIR指向整个内核目录,然后构建您的模块.
As a trial (after downloading kernel src) you can change the makefile to point KDIR to the entire kernel dir and then build your module.
这篇关于在Linux中编译内核模块时遇到麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!