LinuxQuestions.org
Visit Jeremy's Blog.
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 05-06-2007, 06:49 PM   #1
skicy
LQ Newbie
 
Registered: Oct 2005
Distribution: Ubuntu/Debian
Posts: 10

Rep: Reputation: 0
simple kernel programming


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


int init_module()
{
printk("Hello, world - this is the kernel speaking\n");

return 0;
}


void cleanup_module()
{
printk("Short is the life of a kernel module\n");
}


This is a very simple program above. However, when I compile it, something wrong happens:

2.cpp:2:26: error: linux/module.h: No such file or directory
2.cpp: In function ‘int init_module()’:
2.cpp:6: error: ‘printk’ was not declared in this scope
2.cpp: In function ‘void cleanup_module()’:
2.cpp:14: error: ‘printk’ was not declared in this scope

Why it can't find the file the program needs? How can I do to run the program successfully?
Thanks in advance!
 
Old 05-06-2007, 08:56 PM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
i imagine you need your kernel source packages installed. search your package manager and it should be easy to install.
 
Old 05-06-2007, 09:38 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Nadroj is correct - you definitely need the kernel source installed. You can check for it/install it with any of the standard package manager tools (rpm, yum, apt: whatever's appropriate for your distro).

You also need some special #define's and include paths: your compile environment for kernel modules is different from the "standard" compile environment, for user programs.

There are a number of good "kernel programming howto's", including this one:

http://www.faqs.org/docs/kernel/

You can also try downloading and building the examples from O'Reilly's Most Excellent "Linux Device Drivers, 3rd Ed":

http://lwn.net/Kernel/LDD3/

'Hope that helps .. PSM
 
  


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 test circuit to learn kernel device driver programming slzckboy Programming 3 01-30-2006 02:12 AM
Simple C programming Spooky Programming 5 10-22-2004 03:16 AM
Simple C Programming Question.. Bolt Programming 6 06-03-2003 12:05 PM

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

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