Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Ubuntu This forum is for the discussion of Ubuntu Linux.


  Search this Thread
Old 06-06-2010, 05:37 AM   #1
Registered: Jun 2009
Location: Egypt
Distribution: Ubuntu 10.04
Posts: 117

Rep: Reputation: 16
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.
Old 06-07-2010, 02:19 PM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
1 members found this post helpful.
Old 06-08-2010, 03:18 AM   #3
Registered: Jun 2009
Location: Egypt
Distribution: Ubuntu 10.04
Posts: 117

Original Poster
Rep: Reputation: 16
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. :-)
Old 12-05-2012, 09:18 PM   #4
LQ Newbie
Registered: Dec 2012
Posts: 10

Rep: Reputation: Disabled
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

Last edited by ktnamus; 12-05-2012 at 09:26 PM.


kernel, module, programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling a module separately without compiling entire kernel kushalkoolwal Linux - Kernel 8 08-06-2008 01:45 AM
Error compiling NVIDIA kernel module on kernel Slaco Linux - Hardware 6 10-31-2007 07:57 PM
Help me in compiling kernel module swift_a2002 Programming 1 05-05-2007 02:28 PM
Compiling kernel module for linux kernel 2.4 in 2.6 guam Linux - Software 0 01-13-2005 02:02 AM
Kernel compiling and module compiling tarballed Linux - General 1 12-22-2002 05:31 PM > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 10:42 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration