编译内核模块错误

时间:2016-10-29 15:11:51

标签: c linux kernel

我希望运行此内核模块

代码文件hello.c

#include <linux/module.h>
#include <linux/kernel.h>

int init_module(void) {
   printk(KERN_INFO "Hello world!\n");
   return 0;
}
void cleanup_module(void) {
    printk(KERN_INFO "Goodbye world!\n");
}

我在

下面运行了makefile
obj-m += hello.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

但我收到以下错误

make -C /lib/modules/4.4.0-45-generic/build M=/home/fyousry/Desktop/Untitled Folder 4 modules
make[1]: Entering directory '/usr/src/linux-headers-4.4.0-45-generic'
arch/x86/Makefile:148: CONFIG_X86_X32 enabled but no binutils support
Makefile:676: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not supported by compiler
make[1]: *** No rule to make target 'Folder'.  Stop.
make[1]: Leaving directory '/usr/src/linux-headers-4.4.0-45-generic'
Makefile:3: recipe for target 'all' failed
make: *** [all] Error 2

3 个答案:

答案 0 :(得分:0)

包含此代码的目录有空格 当我删除空格时,它是有用的(echo /?而不是for /?

答案 1 :(得分:0)

在给出命令路径时应该使用双引号,尤其是路径包含子命令或变量时。 例如:

make -C "/lib/modules/$(shell uname -r)/build" "M=$(PWD)" modules

答案 2 :(得分:0)

如果你想让它保持间隔,你也可以逃避空间:

make -C /lib/modules/4.4.0-45-generic/build M=/home/fyousry/Desktop/Untitled\ Folder\ 4 modules