You are not logged in.

#1 2016-08-25 18:04:58

Frynio
Member
Registered: 2016-08-24
Posts: 13

Cannot compile simple Kernel module

Hi. So I was reading some online book about making kernel modules. So I got my code:

/*
 *  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");
}

And 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

The console output is:

[frynio@archlinux kernel]$ make
make -C /lib/modules/4.7.1-1-ARCH/build M=/home/frynio/Desktop/dev/kernel modules
make[1]: Entering directory '/usr/lib/modules/4.7.1-1-ARCH/build'
make[1]: *** No rule to make target 'modules'.  Stop.
make[1]: Leaving directory '/usr/lib/modules/4.7.1-1-ARCH/build'
make: *** [Makefile:4: all] Error 2

What am I doing wrong?

Offline

#2 2016-08-25 18:34:14

laloch
Member
Registered: 2010-02-04
Posts: 186

Re: Cannot compile simple Kernel module

Hello Frynio, you most probably need to install linux-headers package.

Offline

#3 2016-08-25 18:54:56

Frynio
Member
Registered: 2016-08-24
Posts: 13

Re: Cannot compile simple Kernel module

Thank you, I'm so dumb, gosh

Offline

#4 2016-08-25 18:59:21

laloch
Member
Registered: 2010-02-04
Posts: 186

Re: Cannot compile simple Kernel module

No problem smile
Please mark the thread as solved and enjoy your kernel hacking.

Offline

Board footer

Powered by FluxBB