-   Ubuntu (
-   -   Help compiling kernel module (

NightHorse 06-06-2010 05:37 AM

Help compiling kernel module
I am trying to write kernel modules. And am running Ubuntu 10.04 x64. I have downloaded both kernel source and headers. Unpacked kernel source and made a /usr/src/linux symbolic link pointing to the src.

Here is the output of running make:

make -C /lib/modules/2.6.32-22-generic/build M= modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-22-generic'
  CHK    include/linux/version.h
  CHK    include/linux/utsrelease.h
  SYMLINK include/asm -> include/asm-x86
make[2]: *** No rule to make target `kernel/bounds.c', needed by `kernel/bounds.s'.  Stop.
make[1]: *** [prepare0] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-22-generic'
make: *** [all] Error 2

Here is my Makefile:

obj-m += hello-1.o

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

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

And here is my simple module:

#include <linux/module.h>        /* Needed by all modules */
#include <linux/kernel.h>        /* Needed for KERN_INFO */

int init_module (void)
        printk (KERN_INFO "Hello world 1.\n");
        * A non 0 return means init_module failes; module can't be loaded.
        return 0;

void cleanup_module (void)
        printk (KERN_INFO "Good night world 1.\n");

I am taking both the module and the Makefile from Linux Kernel Module Programming Guide book. I don't know what am missing. So any help would be appreciated.

Thanks in advance.

paulsm4 06-07-2010 02:19 PM

Hi -



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


Actual output:

make -C /lib/modules/2.6.32-22-generic/build M= modules

It looks like your "pwd" command isn't working.

Did you alias it to something in your user environment?

'Hope that helps .. PSM

NightHorse 06-08-2010 03:18 AM

Thanks a lot for identifying my problem... I changed the $(pwd) to either $(PWD) or $(shell pwd) and both works.. Seems I have to use $(shell command) syntax to run a command in Makefiles or it consider it a variable. I thought it's like shell scripts.

Now it all works, Thanks again. :-)

ktnamus 12-05-2012 09:18 PM

same problem with same make file
i tried both $(PWD) & $(shell pwd). it does not work.and it is not including SYMLINK as SYMLINK include/asm -> include/asm-x86

All times are GMT -5. The time now is 06:40 AM.