【发布时间】:2019-06-25 11:53:49
【问题描述】:
我第一次尝试编译一个简单的内核模块:
#include <linux/module.h>
#include <linux/kernel.h>
int init_nodule(void)
{
printk(KERN_INFO "Hello world1.\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye\n");
}
我使用了obj-m += hello-1.o(这是模块的名称),但出现错误:
obj-m:找不到命令
为什么会这样?我尝试在网上寻找解决方案,但没有找到任何帮助..
编辑:根据@Mathieu answer修改后,出现以下错误:
> make -C /lib/modules/4.18.0-15-generic/build M=/home/galco modules
make[1]: Entering directory '/usr/src/linux-headers-4.18.0-15-generic'
Makefile:970: "Cannot use CONFIG_STACK_VALIDATION=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel"
scripts/Makefile.build:45: /home/galco/Makefile: No such file or directory
make[2]: *** No rule to make target '/home/galco/Makefile'. Stop.
Makefile:1534: recipe for target '_module_/home/galco' failed
make[1]: *** [_module_/home/galco] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.18.0-15-generic'
makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
【问题讨论】:
-
你能完整地发布你的makefile吗?以及如何启动构建?
-
我只是从 ubuntu 终端运行该命令。你的意思是我如何启动构建? @Mathieu
-
看我的回答,
obj-m:...行是make指令... -
请安装 libelf-dev、libelf-devel 或 elfutils-libelf-devel
-
@CacahueteFrito 我做了,但现在它说它找不到 Makefile 文件..
标签: c linux ubuntu makefile linux-kernel