LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   error while compiling a module (https://www.linuxquestions.org/questions/linux-newbie-8/error-while-compiling-a-module-4175508578/)

shri8 06-20-2014 12:24 AM

error while compiling a module
 
for a simple module i used this code
#include <linux/module.h>



/* Defines the license for this LKM */

MODULE_LICENSE("GPL");



/* Init function called on module entry */

int my_module_init( void )

{

printk(KERN_INFO "my_module_init called. Module is now loaded.\n");



return 0;

}



/* Cleanup function called on module exit */

void my_module_cleanup( void )

{

printk(KERN_INFO "my_module_cleanup called. Module is now unloaded.\n");



return;

}



/* Declare entry and exit functions */

module_init( my_module_init );

module_exit( my_module_cleanup );

then in makefile i had obj-m += simple-lkm.o
then i used this
$ make -C /usr/src/linux-`uname -r` SUBDIRS=$PWD modules
make: *** /usr/src/linux-2.6.32-46-server: No such file or directory. Stop.
$
What is the problem in this?

a4z 06-20-2014 12:48 AM

you change into src a directory that does not exist but you should go into the module directory

take this makefile

Code:



ifneq ($(KERNELRELEASE),)

        obj-m := simple-lkm.o

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

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

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

endif


shri8 06-20-2014 01:12 AM

I tried this makefile but stil am getting the same error

a4z 06-20-2014 10:29 AM

if you call make like this
make -C /usr/src/linux-`uname -r` ....
than it is very possible that it will not work

make -C tells make to change into the directory given..
and it seems that you do not have /usr/src/linux-2.6.32-46-serve
and you do usually not want to run make for a module there.

try just make in the directory with your module file and the makefile posted,

shri8 06-21-2014 10:34 AM

error while compiling a module
 
could you be more clear how should the make be?

a4z 06-21-2014 11:28 AM

your/directory
- Makefile (whith the content I posted)
- modulefile.c (with your code)

cd your/directory
make

hth

shri8 06-22-2014 11:10 PM

thanks it worked.I want to know how to write the code for getting running time of a process and put it into this module?


All times are GMT -5. The time now is 06:24 PM.