Results 1 to 5 of 5
I have compile the hello program,but failed. in my directory hello, I have include and src directory. In include directory there is hello.h file. In src directory ,there are hello.c ...
- 05-28-2006 #1Just Joined!
- Join Date
- May 2006
- Posts
- 7
how write my Makefile for a hello kernel module
I have compile the hello program,but failed. in my directory hello, I have include and src directory. In include directory there is hello.h file. In src directory ,there are hello.c Makefile fils.
my hello.h file is as bellow:
#ifndef HELLO_H
#define HELLO_H
#define A 10
#endif
My hello.c is as bellow:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include "hello.h"
MODULE_LICENSE("GPL");
static int hello_init(void)
{
printk("Hello World!\n");
printk("a=%d\n", A);
return 0;
}
static void hello_exit(void)
{
printk("Good bye!\n");
}
module_init(hello_init);
module_exit(hello_exit);
My Makfile is as bellow:
KDIR:=/lib/modules/$(shell uname -r)/build
PWD :=$(shell pwd)
obj-m:=hello.o
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
$(RM) .*.cmd *.o *.ko -r .tmp*
when i was in src directory , i run make ,but have some errons;
[y041138@302wan hello]$ make
make -C /lib/modules/2.6.8.1/build SUBDIRS=/home/y041138/hello modules
make[1]: Entering directory `/usr/src/linux-2.6.8.1'
CC [M] /home/y041138/hello/hello.o
/home/y041138/hello/hello.c:4:19: hello.h: No such file or directory
/home/y041138/hello/hello.c: In function `hello_init':
/home/y041138/hello/hello.c:10: error: `A' undeclared (first use in this functi)
/home/y041138/hello/hello.c:10: error: (Each undeclared identifier is reported e
/home/y041138/hello/hello.c:10: error: for each function it appears in.)
make[2]: *** [/home/y041138/hello/hello.o] Error 1
make[1]: *** [_module_/home/y041138/hello] Error 2
make[1]: Leaving directory `/usr/src/linux-2.6.8.1'
make: *** [default] Error 2
[y041138@302wan hello]$
there is hello.h file in include ,why said that there is no hello.h file??
I guess there is something wrong in my Makefile
can you help me ,and write a right Makefile or let me get pass the compiler
but if the hell.h hell.c Makefile are in the same directory, i can pass the compile if i run make in the src directory.
- 05-29-2006 #2Just Joined!
- Join Date
- Mar 2006
- Posts
- 9
umm..mm I suppost that ,you should to insert __int and __exit macro at init module func. and also cleanup....Code:obj-m := hello.o KDIR := /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) default: $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
ps. in case of you have only one object file
- 07-28-2008 #3Just Joined!
- Join Date
- Dec 2007
- Posts
- 29
hi, how we define compiler optimazation e.g. -O2 in this makefile?
thanks
- 07-29-2008 #4
Check this article's Makefile - It worked for me
http://tldp.org/LDP/lkmpg/2.6/html/- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 07-29-2008 #5Just Joined!
- Join Date
- Dec 2007
- Posts
- 29
it does not help the above link. sorry.
but I think i found it, check
http://i.cs.hku.hk/~chyu/linux/modules.html


Reply With Quote
