LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-20-2014, 12:24 AM   #1
shri8
LQ Newbie
 
Registered: Jun 2014
Posts: 22

Rep: Reputation: Disabled
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?
 
Old 06-20-2014, 12:48 AM   #2
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,315

Rep: Reputation: 552Reputation: 552Reputation: 552Reputation: 552Reputation: 552Reputation: 552
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
 
Old 06-20-2014, 01:12 AM   #3
shri8
LQ Newbie
 
Registered: Jun 2014
Posts: 22

Original Poster
Rep: Reputation: Disabled
I tried this makefile but stil am getting the same error
 
Old 06-20-2014, 10:29 AM   #4
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,315

Rep: Reputation: 552Reputation: 552Reputation: 552Reputation: 552Reputation: 552Reputation: 552
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,
 
Old 06-21-2014, 10:34 AM   #5
shri8
LQ Newbie
 
Registered: Jun 2014
Posts: 22

Original Poster
Rep: Reputation: Disabled
error while compiling a module

could you be more clear how should the make be?
 
Old 06-21-2014, 11:28 AM   #6
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,315

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

cd your/directory
make

hth
 
1 members found this post helpful.
Old 06-22-2014, 11:10 PM   #7
shri8
LQ Newbie
 
Registered: Jun 2014
Posts: 22

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


Reply

Tags
linux


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 module error esmn Programming 1 05-26-2012 10:01 AM
Error during kernel module compiling kususe Linux - Newbie 1 03-13-2011 09:50 AM
Invalid module error after compiling Acronis module cryogenica Linux - General 2 03-17-2008 04:23 PM
error compiling a perl module? waelaltaqi Linux - Software 2 03-15-2008 02:12 PM
compiling a module: how do I resolve this error? scorpion_gr Linux - Software 15 11-20-2006 03:33 PM


All times are GMT -5. The time now is 09:06 AM.

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