Compiling issue

Andi Hellmund mail@andihellmund.com
Mon Jun 8 19:06:00 GMT 2009


Hey,

you need to compile your kernel module within the kernel environment of
your running kernel (or whatever kernel the module is supposed to run
on) which means that you would require the kernel headers and the kernel
build make file.

Check this documentation about kernel modules for Linux 2.6:
http://www.tldp.org/LDP/lkmpg/2.6/html/index.html

A sample make file (http://www.tldp.org/LDP/lkmpg/2.6/html/x181.html)
  
      make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

The -C argument must point to your Linux headers (including Makefile),
while the M= argument points to your own build directory.

Hope that helps.

Andi






abhi_elementx 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");
>    /* A non 0 return means init_module failed; module can't be loaded. */
>    return 0;
> }
>
> void cleanup_module(void){
>   printk("<1>Goodbye world 1.\n");
> }
>
> when I comile 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’:
> hello-1.c:19: error: ‘KERN_ALERT’ undeclared (first use in this function)
> hello-1.c:19: error: (Each undeclared identifier is reported only once
> hello-1.c:19: error: for each function it appears in.)
> hello-1.c:19: error: expected ‘)’ before string constant
>
> how do i solve this?
> Thank you.
>   



More information about the Gcc-help mailing list