LinuxQuestions.org
Visit Jeremy's Blog.
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 04-27-2010, 07:55 PM   #1
aarsh
Member
 
Registered: Mar 2010
Location: ATL, GA
Distribution: openSUSE 11.2 , salckware ,ubuntu
Posts: 169

Rep: Reputation: 18
Question How to add my own module?


Hi I've tried this on my ubuntu 9.04 :

#include <linux/module.h>
#include <linux/config.h>
#include <linux/init.h>

static int __init mymodule_init(void)
{
printk ("My module worked!\n");
return 0;
}

static void __exit mymodule_exit(void)
{
printk ("Unloading my module.\n");
return;
}

module_init(mymodule_init);
module_exit(mymodule_exit);

MODULE_LICENSE("GPL");

and saved this file as module_1.c

and tried to compile this by $gcc module_1.c
but it gives me following error(s) :

expectedd ) bofore _init
expected declaration specifiers or ‘...’ before string constant

Can any on e please help me ??

ALSO ...

from this ...
How to ??

- generate and edit the makefile in the same directory?
- Compile this module
--> please explain, what to understand by
"# make -C [top directory of your kernel source] SUBDIRS=$PWD modules"
- Load the module (is it ? # insmod ./mymodule.o)
- And how to make the kernel to call my this newly created module?


Will my current kernel modules be affected by this?

Last edited by aarsh; 04-27-2010 at 07:57 PM.
 
Old 04-28-2010, 12:49 AM   #2
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,679
Blog Entries: 29

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
Quote:
and tried to compile this by $gcc module_1.c
Hi,
Read the below thread in detail and see if it helps you somehow !
http://www.linuxquestions.org/questi...eaders-770902/
 
Old 04-28-2010, 03:33 AM   #3
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
hi this is not a normal C file so you can not complile just by using gcc. you need to pass other parameters also.
To learn more about module programming you can go through
http://tldp.org/LDP/lkmpg/2.6/html/index.html

To compile this code....

http://tldp.org/LDP/lkmpg/2.6/html/x181.html
 
  


Reply


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
Add Kernel Module Toods Slackware 2 02-15-2006 10:40 AM
Add Module, ALSA PhuckFonix Linux - General 33 08-21-2004 10:56 AM
How to add a source module abd_bela Debian 1 10-26-2003 10:01 AM
how to add a module abd_bela Linux - Hardware 1 10-25-2003 02:26 AM
how to add a new module abd_bela Linux - Hardware 1 09-12-2003 01:59 PM


All times are GMT -5. The time now is 05:48 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