Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-27-2010, 08:55 PM   #1
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");



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 08:57 PM.
Old 04-28-2010, 01:49 AM   #2
Senior Member
Registered: Dec 2008
Posts: 4,680
Blog Entries: 29

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
and tried to compile this by $gcc module_1.c
Read the below thread in detail and see if it helps you somehow !
Old 04-28-2010, 04:33 AM   #3
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

To compile this code....


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

All times are GMT -5. The time now is 01:30 PM.

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