Linux内核模块编译
我尝试编译简单的 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");
}
我的 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
现在我的 .c 文件中没有错误。
但是当我尝试在终端中 make 时: make: Nothing to be do for `all'。
怎么了?
谢谢。
I try to compile simple linux kernel module:
#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:
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.
But when i try make in terminal: make: Nothing to be done for `all'.
What's wrong?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
makefile 中的默认命令是
指示 make cd 到 /lib/modules/$(KVERSION)/build 并运行
反过来,该 makefile 找不到任何可做的事情。据推测,该 makefile 期望在当前目录中找到某些特定结构。
您需要更仔细地阅读引导您设置此 makefile 的所有说明。
The default command in your makefile is
That instructs make to cd to /lib/modules/$(KVERSION)/build and run
In turn, that makefile is not finding anything to do. Presumably, that makefile expects to find some particular structure in your current directory.
You need to more carefully read whatever instructions led you to set up this makefile.
您确实没有提供足够的信息来确定正确答案,但我会给您一些需要研究的内容。
你如何编译它?您的构建中是否有正确的包含路径?构建路径是使用 gcc 的
-I
选项指定的。确保您指向内核源代码树。你构建了内核吗?当您执行
make
时,会进行某些设置以允许您进行构建。执行make
并不会构建所有内容(例如模块),但会为您提供初始设置。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. 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. Doing amake
doesn't build everything (like modules) but will get the initial stuff setup for you.确保您的发行版安装了提供这些包含文件的内核头文件/开发包。
如果已安装,请搜索这些包含文件在计算机上的位置,并将这些目录添加到编译器包含搜索路径(
-I
选项)。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).这是因为你的 Makefile 在给出 make 命令之前不包含制表符
所以通常你的文件应该如下所示:
This is because your Makefile contains no tab before giving make command
So normally your file should be like below: