【问题标题】:Issue while compiling make file for linux kernel?为linux内核编译make文件时出现问题?
【发布时间】:2013-09-27 00:49:40
【问题描述】:

我刚刚开始进行 linux 内核开发,但在编译 make 文件时遇到了问题。

这是hello world的教程。

我的 hello-1.c 文件

*
* hello−1.c − The simplest kernel module.
*/
#include <linux/module.h>
/* Needed by all modules */
#include <linux/kernel.h>
/* Needed for KERN_INFO */
int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}

我的 Makefile

obj−m += hello−1.o

all:
        make −C /lib/modules/$(shell uname −r)/build M=$(PWD) modules

clean:
        make −C /lib/modules/$(shell uname −r)/build M=$(PWD) clean

这两个文件都在文件夹/home/kkr/Documents/HelloWorld中

当我运行 make 命令时,我得到以下输出。

uname: extra operand `−r'
Try `uname --help' for more information.
make −C /lib/modules//build M=/home/kkr/Documents/HelloWorld modules
make[1]: Entering directory `/home/kkr/Documents/HelloWorld'
make[1]: *** No rule to make target `−C'.  Stop.
make[1]: Leaving directory `/home/kkr/Documents/HelloWorld'
make: *** [all] Error 2

任何人都知道根本原因是什么吗?我知道这很简单,但我还是无法从中走出来?

谢谢

【问题讨论】:

  • 这真的是你Makefile的格式吗?如果是,则格式不正确。命令应该在包含目标和依赖项的行之后缩进一个制表符。
  • @mbratch 不,不是。实际上,在发布问题时我做了 ctrl+k 可能是删除标签。我再次编辑了问题。

标签: c linux ubuntu makefile linux-kernel


【解决方案1】:
$(shell uname −r)
              ^
           This is not a - (dash , minus) character.

你想要的

$(shell uname -r)

【讨论】:

  • 哦!很好的观察,我也为 C 做了同样的事情。但我做到了,它也编译得很好。谢谢
  • 出于好奇,您是如何发现的?你刚刚看到了吗?
  • @Étienne 只需将其复制粘贴到终端以运行 uname -r ,但失败了,然后我自己输入了有效的命令。
【解决方案2】:

我最初也遇到过同样的问题。

不应复制 Makefile 的内容。 复制会更改一些字符,因此“make”命令将无法识别它们。

要正确构建模块,您需要在 Makefile 中手动键入代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多