简体   繁体   English

Linux内核模块编译

[英]Linux kernel module compiling

I try to compile simple linux kernel module: 我尝试编译简单的linux内核模块:

#include <linux/module.h>    
#include <linux/kernel.h>       

int init_module(void)
{
        printk("Hello world 1.\n");
        return 0;
}

void cleanup_module(void)
{
        printk(KERN_ALERT "Goodbye world 1.\n");
}

My makefile: 我的makefile:

obj-m = testmodule.o
KVERSION = $(shell uname -r)
all:
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

Now i haven't errors in my .c file. 现在,我的.c文件中没有错误。

But when i try make in terminal: make: Nothing to be done for `all'. 但是,当我尝试在终端中进行make时:make:对于all而言,什么也没做。

What's wrong? 怎么了?

Thank you. 谢谢。

The default command in your makefile is 您的makefile中的默认命令是

make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules

That instructs make to cd to /lib/modules/$(KVERSION)/build and run 指示make将cd转到/ lib / modules / $(KVERSION)/ build并运行

make module m=YOUR_CURRENT_DIR

In turn, that makefile is not finding anything to do. 反过来,该makefile没有找到任何要做的事情。 Presumably, that makefile expects to find some particular structure in your current directory. 大概该makefile期望在当前目录中找到某些特定结构。

You need to more carefully read whatever instructions led you to set up this makefile. 您需要更仔细地阅读导致您设置此makefile的说明。

You really don't give enough information to determine the correct answer, but I'll give you some things to look into. 您确实没有提供足够的信息来确定正确的答案,但我会给您一些注意事项。

How are you compiling it? 您如何编译? Do you have the correct include path in your build? 您的构建中是否包含正确的包含路径? Build paths are specified with the -I option to gcc. 使用gcc的-I选项指定构建路径。 Make sure you are pointing to your kernel source tree. 确保您指向内核源代码树。

Have you build the kernel? 您是否已构建内核? When you do a make , certain things are setup that allows you to build. 当您进行make ,将设置一些允许您构建的东西。 Doing a make doesn't build everything (like modules) but will get the initial stuff setup for you. 做一个make并不能构建所有内容(例如模块),但是会为您提供初始的东西设置。

Make sure your have your distributions the kernel header/development packages installed that provide these include files. 确保已经分发了安装了包含这些头文件的内核头文件/开发包。

If they are installed, search where these include files are located on your computer and add these directories to your compilers include search path (the -I option). 如果已安装,请搜索这些包含文件在计算机上的位置,然后将这些目录添加到编译器的包含搜索路径( -I选项)。

This is because your Makefile contains no tab before giving make command 这是因为在发出make命令之前,您的Makefile不包含任何选项卡

make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules

So normally your file should be like below: 因此,通常您的文件应如下所示:

obj-m = test.o                                                                   

KVERSION = $(shell uname -r)                                                     

all:                                                                             
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules                  
clean:                                                                           
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM