我在Linux Ubuntu 14.04上。我想啓動Linux Kernel Module Programming。我有hello.c(簡單的Hello World模塊)和Makefile。但是,在「make」命令中,我會遇到錯誤。我試過Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not supported by compiler,但它不適合我。Linux內核模塊編程 - 無法使用CONFIG_CC_STACKPROTECTOR_REGULAR:編譯器不支持-fstack-protector
的hello.c
/* hello.c − Illustrating the __init, __initdata and __exit macros. */
#include <linux/module.h>
/* Needed by all modules */
#include <linux/kernel.h>
/* Needed for KERN_INFO */
#include <linux/init.h>
/* Needed for the macros */
static int hello3_data __initdata = 3;
static int __init hello_3_init(void)
{
printk(KERN_INFO "Hello, world %d\n", hello3_data);
return 0;
}
static void __exit hello_3_exit(void)
{
printk(KERN_INFO "Goodbye, world 3\n");
}
module_init(hello_3_init);
module_exit(hello_3_exit);
的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
在 「做」: -
[email protected]:~/Kernel programs$ make
make -C /lib/modules/4.2.0-27-generic/build M=/home/k/Kernel programs modules
make[1]: Entering directory `/usr/src/linux-headers-4.2.0-27-generic'
arch/x86/Makefile:138: CONFIG_X86_X32 enabled but no binutils support
Makefile:662: Cannot use CONFIG_CC_STACKPROTECTOR_REGULAR: -fstack-protector not supported by compiler
make[1]: *** No rule to make target `programs'. Stop.
make[1]: Leaving directory `/usr/src/linux-headers-4.2.0-27-generic'
make: *** [all] Error 2
目前,我的Ubuntu有4.2內核。我甚至在3.x內核上試過這個,但是也有這個錯誤。
請幫我這個。謝謝。 :)
'我試過......但它對我沒有用處。「 - 因此,正如所引用問題的答案中所示,您已更新'binutils'並安裝了'gcc'的唯一實例,並且'g ++'編譯器,對吧? – Tsyvarev
是的,我做了所有這一切 –