I am trying to create a simple make file and using it to build a simple c program. The environment is in virtual box using the newest version of ubuntu. I have already downloaded the linux headers for ubuntu but still getting the error.
Hello.c
#include <linux/init.h>
#include <linux/module.h>
static int hello_init(void) {
printk(KERN_ALERT "TEST: Hello world, this is soliducode\n");
return 0;
}
static void hello_exit(void) {
printk(KERN_ALERT "TEST: Good byte, from soliduscode");
}
module_init(hello_init);
module_exit(hello_exit);
Makefile
obj-m += Hello.o
KDIR = /usr/src/linux-headers-4.2.0-16-generic
all:
$(MAKE) -C $(KDIR) SUBSIRS=$ modules
clean:
rm -rf *.o *.ko *.mod.* *.symvers *.order
Error
make -C /usr/src/linux-headers-4.2.0-16-generic SUBSIRS=modules
make[1]: Entering directory '/usr/src/linux-headers-4.2.0-16-generic'
arch/x86/Makefile:138: CONFIG_X86_X32 enabled but no binutils support
Makefile:669: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not supported by compiler
HOSTCC scripts/basic/fixdep
scripts/basic/fixdep.c:462:1: fatal error: opening dependency file scripts/basic/.fixdep.d: Permission denied
}
^
compilation terminated.
scripts/Makefile.host:91: recipe for target 'scripts/basic/fixdep' failed
make[3]: *** [scripts/basic/fixdep] Error 1
Makefile:449: recipe for target 'scripts_basic' failed
make[2]: *** [scripts_basic] Error 2
make[2]: *** No rule to make target 'arch/x86/entry/syscalls/syscall_32.tbl', needed by 'arch/x86/entry/syscalls/../../include/generated/asm/syscalls_32.h'. Stop.
arch/x86/Makefile:184: recipe for target 'archheaders' failed
make[1]: *** [archheaders] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.2.0-16-generic'
Makefile:6: recipe for target 'all' failed
make: *** [all] Error 2
It looks like your kernel config is invalid.
There is documentation how to build your own kernel on Ubuntu, e.g. https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel