LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 07-12-2003, 02:26 PM   #1
Electboy
Member
 
Registered: May 2003
Location: VietNam
Distribution: RedHat 9.0
Posts: 79

Rep: Reputation: 15
Need help!!!


include <linux/module.h>
include <linux/kernel.h>

but error happened when i used printk() : like as "need library for printk()"
Any one has idea ?
 
Old 07-12-2003, 02:40 PM   #2
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
Make sure that the include lines are as follows:
Code:
#include <linux/module.h>
#include <linux/kernel.h>
The #'s are important!

Also, there might be some libraries required to link in with your binary, since you're doing kernel stuff.. I really have no clue, since I've never done anything with the kernel. You might post the command you gave when compiling the source, and the error messages returned.
 
Old 07-12-2003, 02:47 PM   #3
Electboy
Member
 
Registered: May 2003
Location: VietNam
Distribution: RedHat 9.0
Posts: 79

Original Poster
Rep: Reputation: 15
Yes...i typed without "#" in my question. Any else about my problem?
 
Old 07-12-2003, 02:50 PM   #4
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
can you post your code, the command you used to compile, and the error it gave.

stupid question: you are only compiling and not linking the module arnt you? modules are linked at runtime by insmod so you must specify the -c option to gcc

Last edited by kev82; 07-12-2003 at 02:52 PM.
 
Old 07-12-2003, 02:50 PM   #5
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
What command did you use to compile the binary? What error messages did it return? Can you post them exactly?
 
Old 07-13-2003, 12:13 PM   #6
Electboy
Member
 
Registered: May 2003
Location: VietNam
Distribution: RedHat 9.0
Posts: 79

Original Poster
Rep: Reputation: 15
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void)
{
printk("<1>Hello world 1.\n");
return 0;}
void cleanup_module(void)
{
printk(KERN_ALERT "Goodbye world 1.\n");
}

That is my code.
 
Old 07-13-2003, 01:42 PM   #7
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
Quote:
can you post your code, the command you used to compile, and the error it gave
the command you used to compile would be good as would the error you get. i can compile your code(or rather peter salzman's) with no problem
 
Old 07-13-2003, 01:49 PM   #8
Electboy
Member
 
Registered: May 2003
Location: VietNam
Distribution: RedHat 9.0
Posts: 79

Original Poster
Rep: Reputation: 15
what kernel and Linux are u using ? mine is 2.4.20, Redhat 9. The command is
gcc -c -O2 -Wall -isystem /lib/modules/`uname -r`/build/include -D__KERNEL__ -DMODULE hello.o hello.c
 
Old 07-13-2003, 01:57 PM   #9
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
i have compiled it with kernel 2.4.19, my system is totally compiled from source.

i used the following command:
gcc -c -O2 -D__KERNEL__ -DMODULE -isystem /lib/modules/2.4.19/build/include/ mod.c

how about sharing the error you got with me?
 
Old 07-13-2003, 02:09 PM   #10
Electboy
Member
 
Registered: May 2003
Location: VietNam
Distribution: RedHat 9.0
Posts: 79

Original Poster
Rep: Reputation: 15
thank you kev82. Please open the kernel.h and search "printk" or "KERN_ALERT".
 
Old 07-13-2003, 02:23 PM   #11
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
both are defined
 
Old 07-13-2003, 02:27 PM   #12
Electboy
Member
 
Registered: May 2003
Location: VietNam
Distribution: RedHat 9.0
Posts: 79

Original Poster
Rep: Reputation: 15
OH really? but they are not defined in my kernel.h, kernel 2.4.20
 
Old 07-13-2003, 02:33 PM   #13
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
ive checked a machine running 2.4.20 both are defined in its kernel.h, most likely when you installed you or the installer neglected to install the appropriate files for kernel development, someone on a red hat forum might be able to help you with this but ive never used it so i dont know.
 
Old 07-13-2003, 03:07 PM   #14
Electboy
Member
 
Registered: May 2003
Location: VietNam
Distribution: RedHat 9.0
Posts: 79

Original Poster
Rep: Reputation: 15
Thank you all your help kev82. I think i will have to recompile my kernel
 
  


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



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

All times are GMT -5. The time now is 06:19 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
Open Source Consulting | Domain Registration