0
votes

I'm building a sample kernel module under linux . The module sources are "out of the kernel tree". I've got kernel source tree from git. But it takes time to configure the kernel. So at this moment i'm just trying to build the module against kernel headers provided by my Distribution.

My Makefile :

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


   $(info Building with KERNELRELEASE = ${KERNELRELEASE})
  obj-m := hello.o

But make stops with reporting that i could not find etc, that means it could not find the headers.

but the files are there :

 $ls /lib/modules/$(uname -r)/build
 $arch  block  crypto  drivers  firmware  fs  include  init  ipc  kernel  lib  Makefile             Makefile.common  mm  Module.symvers  net  samples  scripts  security  sound  System.map  tools  usr  virt

I guess its a trivial problem. But still i could not find the solution.

Thanks in advance.

EDIT: Errors :

Building with KERNELRELEASE =
make -C /lib/modules/2.6.32-220.el6.x86_64/build/  M=/usr/local/src/kernel_mods
make[1]: Entering directory `/usr/src/kernels/2.6.32-220.el6.x86_64'
Building with KERNELRELEASE = 2.6.32-220.el6.x86_64
  LD      /usr/local/src/kernel_mods/built-in.o
  CC [M]  /usr/local/src/kernel_mods/hello.o
/usr/local/src/kernel_mods/hello.c:2:27: error: linux/modules.h: No such file or directory
/usr/local/src/kernel_mods/hello.c:21: error: expected declaration specifiers or â...â before string constant
/usr/local/src/kernel_mods/hello.c:21: warning: data definition has no type or storage class
/usr/local/src/kernel_mods/hello.c:21: warning: type defaults to âintâ in declaration of âMODULE_LICENSEâ
/usr/local/src/kernel_mods/hello.c:21: warning: function declaration isnât a prototype
/usr/local/src/kernel_mods/hello.c:22: error: expected declaration specifiers or â...â before string constant
/usr/local/src/kernel_mods/hello.c:22: warning: data definition has no type or storage class
/usr/local/src/kernel_mods/hello.c:22: warning: type defaults to âintâ in declaration of âMODULE_AUTHORâ
/usr/local/src/kernel_mods/hello.c:22: warning: function declaration isnât a prototype
/usr/local/src/kernel_mods/hello.c:23: error: expected declaration specifiers or â...â before string constant
/usr/local/src/kernel_mods/hello.c:23: warning: data definition has no type or storage class
/usr/local/src/kernel_mods/hello.c:23: warning: type defaults to âintâ in declaration of âMODULE_DESCRIPTIONâ
/usr/local/src/kernel_mods/hello.c:23: warning: function declaration isnât a prototype
make[2]: *** [/usr/local/src/kernel_mods/hello.o] Error 1
make[1]: *** [_module_/usr/local/src/kernel_mods] Error 2
make[1]: Leaving directory `/usr/src/kernels/2.6.32-220.el6.x86_64'
make: *** [all] Error 2
1
Can you add the exact error message from Make? - Kristof Provost

1 Answers

3
votes

I think you meant to do

#include <linux/module.h>

rather than

#include <linux/modules.h>