2

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/Makefile.build:76: kbuild: Makefile.build 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 
all: 
     make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules 
clean: 
     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: Makefile.build is included improperly)
endif

i hope this helps solve the issue.

5
  • 1
    Given that I have a file named /usr/src/linux-2.6.38.2/kernel/bounds.c 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, 2012 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, 2012 at 18:01
  • @gnometorule i have added the makefile ...
    – Chani
    Jan 4, 2012 at 18:03
  • @gnometorule there was no change in the error after i did what you suggested in your answer ..
    – Chani
    Jan 4, 2012 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, 2016 at 20:35

1 Answer 1

2

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:

ifeq ($(KERNELRELEASE),)

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

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

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

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

.PHONY: modules modules_install clean

else
obj-m := hello.o 

endif
3
  • i'll try this .. in the meantime pls go though the part of the question i just edited ..
    – Chani
    Jan 4, 2012 at 18:43
  • still the same error i got
    – Chani
    Jan 4, 2012 at 18:45
  • Create a simple 'hello world' module (per this model, if it differs from yours: lwn.net/Articles/21817. 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. Jan 4, 2012 at 19:19

You must log in to answer this question.

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