LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 11-22-2006, 08:25 AM   #1
linwenyuan
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:
/*hello.c*/
#ifndef MODULE
#define MODULE
#endif
#ifndef __KERNEL__
#define __KERNEL__
#endif
#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");
}
MODULE_LICENSE("GPL");

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, 04:16 AM   #2
isanjaykumar
LQ Newbie
 
Registered: Jan 2005
Location: India
Posts: 2

Rep: Reputation: 0
Hi,
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

~Sanjay
 
Old 11-24-2006, 12:51 AM   #3
someshwar
LQ Newbie
 
Registered: Oct 2006
Posts: 14

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


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


All times are GMT -5. The time now is 07:44 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration