make拒绝构建内核模块

时间:2017-11-27 22:05:59

标签: linux makefile module compilation kernel

我必须为研究项目编写一个简单的Linux内核模块,但我遇到了Makefile的问题。这就是我obj-m := main.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 现在的样子:

main.c

我要编译的源文件名为make,当我在源代码目录中输入root@debian:~/test-module# make make -C /lib/modules/4.9.0-4-amd64/build M=/root/test-module modules make[1]: Entering directory '/lib/modules/4.9.0-4-amd64/build' make[1]: *** No rule to make target 'modules'. Stop. make[1]: Leaving directory '/lib/modules/4.9.0-4-amd64/build' Makefile:6: recipe for target 'all' failed make: *** [all] Error 2 时,我得到了这个输出:

/lib/modules/4.9.0-4-amd64/build

正如输出已经暗示的那样,我正在使用内核4.9.0-4-amd64运行Debian 9。由于我是Makefiles的新手,我无法在文件中找到任何错误。有人可以向我解释我的错误在哪里吗?

更新:经过一番研究后,我发现ln -s /usr/src/linux-source-4.9 /lib/modules/4.9.0-4-amd64/build 必须包含内核源代码树。所以我做了

root@debian:~/test-module# make
make -C /lib/modules/4.9.0-4-amd64/build modules
make[1]: Entering directory '/usr/src/linux-source-4.9'
scripts/kconfig/conf  --silentoldconfig Kconfig
***
*** Configuration file ".config" not found!
***
*** Please run some configurator (e.g. "make oldconfig" or
*** "make menuconfig" or "make xconfig").
***
scripts/kconfig/Makefile:37: recipe for target 'silentoldconfig' failed
make[3]: *** [silentoldconfig] Error 1
Makefile:548: recipe for target 'silentoldconfig' failed
make[2]: *** [silentoldconfig] Error 2

The present kernel configuration has modules disabled.
Type 'make config' and enable loadable module support.
Then build a kernel with module support enabled.

Makefile:1271: recipe for target 'modules' failed
make[1]: *** [modules] Error 1
make[1]: Leaving directory '/usr/src/linux-source-4.9'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2

其中链接的目标目录包含完整的Linux内核源代码树。当我现在运行make时,我得到了这个输出:

make config

看起来比上次好,但仍然无法奏效。我想我只需要在内核源代码树的某个目录中运行 class User{ public $name ; public $age ; public $height ; public $weight ; function __construct($name,$age,$height,$weight){ $this->age = $age; $this->name = $name; $this->height = $height; $this->weight = $weight; } public function ispis(){ echo $this->age; } } $question_array = [new User ("Ivan","22","174","68"), new User("Luka","23","174","68") ]; $daniel = new User($question_array); //$daniel = new User("ivan","22"); $daniel->ispis(); 左右,但我不知道在哪里。我该怎么办?

0 个答案:

没有答案