LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   kernel module makefile problem (https://www.linuxquestions.org/questions/linux-newbie-8/kernel-module-makefile-problem-4175479846/)

shiv garg 10-06-2013 10:55 PM

kernel module makefile problem
 
sir i was trying to make a makefile
but i was not able to do that
module was simple a hello world program

#include<linux/init.h>
#include<linux/module.h>
MODULE_LISENCE("DUAL bSD/GPL");


static int hello_init(void )
{
printk(KERN_ALERT "HELLO WORLD");
return 0;
}


static int hello_exit(void)
{
printk( KERN_ALERT "thankyou cruel sworld");
}



module_init(hello_init);
module_exi(hello_exit);




its name was demo.c


i made a Makefile

obj-m = foo.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


but i ended up on an eror

make -C /lib/modules/3.5.0-23-generic/build M=/home/shiv/Desktop/module modules
make[1]: Entering directory `/usr/src/linux-headers-3.5.0-23-generic'
make[2]: *** No rule to make target `/home/shiv/Desktop/module/foo.c', needed by `/home/shiv/Desktop/module/foo.o'. Stop.
make[1]: *** [_module_/home/shiv/Desktop/module] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.5.0-23-generic'
make: *** [all] Error 2


kindly help

pan64 10-07-2013 01:48 AM

As far as I see the name of your test is demo.c you would try:
obj-m = demo.o # instead of foo.o

shiv garg 10-07-2013 01:54 AM

sir i have tried with demo.o but problem persists

pan64 10-07-2013 02:04 AM

please use [code]here comes your code[/code] blocks to keep your formatting and post your new makefile and the complete error message(s)

knudfl 10-07-2013 05:46 AM

The simple module Makefile looks like this
Code:

obj-m    := demo.o

KDIR    := /lib/modules/$(shell uname -r)/build
PWD    := $(shell pwd)

default:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules


shiv garg 10-18-2013 06:37 AM

sir i have succeeded in compiling the make file sucessfully.. and i have loaded the kernal sucessfully ... but pls tell me that where to look for output...
means hello world is not printed on terminal after loading it on the kernal

pan64 10-18-2013 09:03 AM

see man syslog about how printk handled

Ginola 10-18-2013 10:34 AM

also, isnt that a typo?

Code:

MODULE_LISENCE("DUAL bSD/GPL");

should be MODULE_LICENSE, right?


All times are GMT -5. The time now is 01:22 PM.