Ok here is my code for my make file:
I saved the makefile as hello_world.o
Code:
# Makefile for compiling Kernel
obj-m = hello_world.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
Now here is my hello_world source:
I saved this as hello_world-r.o
Code:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Annonymous");
static int hello_init(void) {
printk(KERN_ALERT "Hello world!\n");
return 0;
}
static void hello_exit(void) {
printk(KERN_ALERT "Goodbye world!\n");
}
module_init(hello_init);
module_exit(hello_exit);
Terminal input/output:
Code:
I cd'd into the dir where the hello_world source is in. Then i tried this on the command line ==> gcc -D__KERNEL__ -DMODULE -I/usr/src/linux-2.4/include -O2 -c hello_world-r.o
It gave the error: gcc: hello_world-r.o: linker input file unused because linking not done
Am I supposed to be doing something with the makefile first?? I'm stumped!!
@brewbuck, that is exactly what I did. I stole the makefile from a random makefile tutorial.
TRY #2:
Code:
I tried renaming the file with the (dot)c extension and then ran this on the command line ==> gcc hello_world-r.c -o hello2
I was given these errors ==>
hello_world.c:1:3: error: invalid preprocessing directive #Makefile
hello_world.c:2:3: error: invalid preprocessing directive #modules
hello_world.c:3:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘-’ token
TRY #3:
Code:
I even tried ==> make -C ~/LKM/
NOTHING