简体   繁体   English

编译linux内核的make文件时出问题?

[英]Issue while compiling make file for linux kernel?

I have just started with linux kernel development and I am having issue with compiling make file. 我刚开始使用linux内核开发,我遇到编译make文件的问题。

It is the tutorial of hello world. 这是你好世界的教程。

My hello-1.c file 我的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");
}

My Makefile 我的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

Both of this file are in folder /home/kkr/Documents/HelloWorld 这个文件都在文件夹/ home / kkr / Documents / HelloWorld中

When i run the make command I am getting below output. 当我运行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

Can any body have any idea what is the root cause ? 任何人都可以知道根本原因是什么? I know it is very simple still I am not able to come out from this ? 我知道这很简单,我还是不能从这里出来?

Thanks 谢谢

$(shell uname −r)
              ^
           This is not a - (dash , minus) character.

You want 你要

$(shell uname -r)

I had faced the same problem initially. 我最初遇到了同样的问题。

The contents of Makefile shouldn't be copied. 不应复制Makefile的内容。 The copying will change some characters so the 'make' command won't recognize them anymore. 复制将更改某些字符,因此'make'命令将不再识别它们。

To properly build the module, you need to manually type the code in Makefile. 要正确构建模块,您需要在Makefile中手动键入代码。

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

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