Reputation: 63
I am having trouble building helloworld Linux kernel module. I am using VirtualBox from SUN with Ubuntu ISO image that I downloaded from Ubuntu web site. Any help will be greatly appreciated. Bellow are the c code and the error message that I am getting:
The module file is called hellowrld.c and it contains the code below:
#include <linux/module.h> // included for all kernel modules
#include <linux/kernel.h> // included for KERN_INFO
#include <linux/init.h> // included for __init and __exit macros
MODULE_LICENSE("GPL");
static int __init helloworld_init(void)
{
printk(KERN_INFO "Hello world!\n");
return 0;
}
static void __exit helloworld_exit(void)
{
printk(KERN_INFO "Cleaning up module.\n");
}
module_init(helloworld_init);
module_exit(helloworld_exit);
The make file is called makefile.c and it contains the code below:
obj -m += helloworld.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 error message that I am getting when I run make command is below:
cc makefile.c -o makefile
makefile.c:1:4: error: expected '=', ',', ';', 'asm' or '__attribute__' before '-' token
obj-m helloworld.o
make: *** No targets specified no makefile found. Stop
Upvotes: 1
Views: 2029
Reputation: 5909
The right Makefile looks like this ...
obj-m := helloworld.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
rm -rf *.o *.ko *.mod.* *.symvers *.order
Upvotes: 4