Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Linux - Kernel This forum is for all discussion relating to the Linux kernel.


  Search this Thread
Old 11-22-2006, 09:25 AM   #1
LQ Newbie
Registered: Sep 2006
Posts: 27

Rep: Reputation: 15
a simple question about module programming

i am new man ,and i want to study module programming ,as a start i test following programming:
#ifndef MODULE
#define MODULE
#ifndef __KERNEL__
#define __KERNEL__
#include <linux/kernel.h>
#include <linux/module.h>
int init_module(void) {
printk("Hello World!\n");
return 0;
void cleanup_module(void) {
printk("Goodbye world!\n");

but when i compile it,it report me these messages:
# cc -O2 -Wall -c hello.c
In file included from /usr/include/linux/module.h:10,
from hello.c:8:
/usr/include/linux/config.h:5:2: error: #error Incorrectly using glibc headers for a kernel module
hello.c: 在函数 ‘init_module’ 中:
hello.c:11: 警告:隐式声明函数 ‘printk’

how to fix the error? (the last two lines is warnning)
any answer would be appreciated very much
Old 11-23-2006, 05:16 AM   #2
LQ Newbie
Registered: Jan 2005
Location: India
Posts: 2

Rep: Reputation: 0
Please compile it as below:

KERNEL_SRC_DIR=<path of ur linux kernel soruce>

cc -O2 -DMODULE -D__KERNEL__ -I $KERNEL_SRC_DIR/include -Wall -c hello.c

Old 11-24-2006, 01:51 AM   #3
LQ Newbie
Registered: Oct 2006
Posts: 14

Rep: Reputation: 0
r u working on 2.4 or 2.6?


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
simple shall programming question itz2000 Programming 1 11-05-2005 05:12 PM
very simple bash programming question!? Thinking Programming 7 06-01-2005 12:07 PM
simple question on shell programming stupid_guy Programming 5 03-10-2004 03:07 PM
Simple C Programming Question.. Bolt Programming 6 06-03-2003 01:05 PM > Forums > Linux Forums > Linux - Software > Linux - Kernel

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