[PLUG] gcc compilation issue

Vaibhav Kulkarni netvaibhav at gmail.com
Mon Jun 8 23:13:21 IST 2009

On Mon, Jun 8, 2009 at 9:36 PM, abhi<abhi.elementx at gmail.com> wrote:
> Hi all. I am trying to learn writing linux modules. I am referring to a book
> for writing the modules in C.
> my code is :
> /*hello-1.c*/
> #include <linux/module.h>  /* Needed by all modules */
> #include <linux/kernel.h>  /* Needed for KERN_ALERT */
> int init_module(void){
>   printk("<1>Hello world 1.\n");
>   return 0;
> }
> void cleanup_module(void){
>  printk("<1>Goodbye world 1.\n");
> }
> when I compile this using :
> $ gcc -c hello-1.c
> It says :
> hello-1.c:4:55: error: linux/module.h: No such file or directory
> hello-1.c: In function ‘cleanup_module’:

Create a file called Makefile in that directory and type the following

# Begin Makefile

obj-m += hello-1.o

# hello-1-objs := module.o

	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

# End makefile

Then type "make" to build.

Later if you're going to add more files as part of the module source,
uncomment the hello-1-objs line and add the appropriate file.o for
each file.c. See some kernel source makefiles for example.



More information about the Plug-mail mailing list