LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-15-2005, 07:29 AM   #1
mohsena
LQ Newbie
 
Registered: Oct 2005
Posts: 3

Rep: Reputation: 0
Problem with writing module


Hello
I am new in making module in linux ,I tried the first module programming as you see as follows
/*
* hello-1.c - The simplest kernel module.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}

Then the tutorials told me for compiling the module I should use the following commands

obj-m += hello-1.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

would you please explain me what is $(sehll uname –r) and M=$(PWD)

Sincerely yours Mohsena
 
Old 10-15-2005, 08:31 AM   #2
zeropash
Member
 
Registered: Apr 2003
Location: Bangalore,India
Distribution: FC2, RHES, RH9, FC3, FC1, Slackware 3.0
Posts: 208

Rep: Reputation: 30
I guess that what you have put above is the Makefile
PS: please put all the code inside <code> </code> tags so that the indendation is clear.
now for makefiles
$(shell uname -r) would run the command uname -r and put the output instead same for M=$(PWD)
so
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
would get replaced by
make -C /lib/modules/2.6.9-1.667/build M=/home/myself/sources/
or something like that where the 2.6... is your version of the kernel and /home/myself/sources is the directory where you have the sources (current directory).
-C instructs the make command to change to the directory before doing anything.
The M=$PWD is used by the build/Makefile
if you check that you will see this line

# Use make M=dir to specify directory of external module to build
 
Old 10-16-2005, 07:01 AM   #3
mohsena
LQ Newbie
 
Registered: Oct 2005
Posts: 3

Original Poster
Rep: Reputation: 0
Hello and thank you very much for your responce
I tried to do what you recommended me as follows
$ make -c /lib/modules/2.6.4-override-default/build M=/home/linux/hello-1.c
but it sent me back the following error:
bach:Make :command nout found
Please help me
sincerely yours Mohsena
 
Old 10-16-2005, 09:51 AM   #4
zeropash
Member
 
Registered: Apr 2003
Location: Bangalore,India
Distribution: FC2, RHES, RH9, FC3, FC1, Slackware 3.0
Posts: 208

Rep: Reputation: 30
I think you have not installed the make package.
try installing that.
and the command is
<code>
make -c /lib/modules/2.6.4-override-default/build M=/home/linux/
</code>
better
just enter the stuff as it to a text file named Makefile and then
do a make
 
  


Reply



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
Tutorial for writing cypher kernel module ta0kira Programming 7 06-19-2011 10:43 PM
the writing problem lfx4linux Ubuntu 2 03-20-2005 12:21 PM
fglrx module not found but X runs using module biger problem though HELP! fireicer Linux - Newbie 4 07-30-2004 04:44 PM
writing to proc module dmaxj Linux - General 5 07-02-2003 09:44 AM
cd writing software which supports multisession writing jayakrishnan Linux - General 3 03-24-2003 05:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:10 PM.

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
Open Source Consulting | Domain Registration