Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I tried to compile my first loadable kernel module and failed :(

Here is the error:

r@ubuntu:/$ sudo make -C /lib/modules/`uname -r`/build/ M=`pwd`
[sudo] password for r: 
make: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
scripts/ kbuild: is included improperly
make[1]: *** No rule to make target `kernel/bounds.c', needed by `kernel/bounds.s'.  Stop.
make: *** [_module_] Error 2
make: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'

I need help knowing what is wrong.

Here is the makefile i am using:

obj-m += sample_module_for_techblog.o 
     make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules 
     make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) clean 
clean-files := Module.symvers

i found out the following piece of code (which is printing the piece of error that i ma getting) from here

ifndef obj
$(warning kbuild: is included improperly)

i hope this helps solve the issue.

share|improve this question

migrated from Jan 4 '12 at 18:21

This question came from our site for professional and enthusiast programmers.

Given that I have a file named /usr/src/linux- on my system, I would suspect that on your system a file named /usr/src/linux-headers-2.6.38-8-generic/kernel/bounds.c is missing, for whatever reason. – PlasmaHH Jan 4 '12 at 17:21
It doesn't come with it - I just checked (for the 37-generic sub number I'm running). I only got the assembly file bounds.s. If I had to guess, this file (these files) are used by the kernel makefile we're accessing. The problem though is almost certainly an issue with the makefile the user is providing, so drunkM: could you please add the makefile you're using? – gnometorule Jan 4 '12 at 18:01
@gnometorule i have added the makefile ... – Wildling Jan 4 '12 at 18:03
@gnometorule there was no change in the error after i did what you suggested in your answer .. – Wildling Jan 4 '12 at 18:33
Related, see BuildYourOwnKernel on the Ubuntu wiki. apt-get source linux-image-$(uname -r) should install the missing sources. – jww Mar 26 at 20:35
up vote 2 down vote accepted

Try this one, adjusted as necessary. I'm not familiar with the tutorial you link in, but assume you created the most basic 'hello world' style module that you try to compile:


    KERNELDIR ?= /lib/modules/$(shell uname -r)/build
    PWD := $(shell pwd)

        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install

# adjust this by removing what applies to you
        rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions \
        *.symvers  *.order 

.PHONY: modules modules_install clean

obj-m := hello.o 

share|improve this answer
i'll try this .. in the meantime pls go though the part of the question i just edited .. – Wildling Jan 4 '12 at 18:43
still the same error i got – Wildling Jan 4 '12 at 18:45
Create a simple 'hello world' module (per this model, if it differs from yours: Please add a line including <linux/init.h> as well), then run this with the code I added above - careful that you obviously adjust for the file names etc that you build. You are digging into inclusions and further steps performed by the kernel level module makefile, which you shouldn't have to. So something is strange, and I'd start by testing something that definitely runs - at least on my Ubuntu distro. There might be slight differences between distros, but not too severely. – gnometorule Jan 4 '12 at 19:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .