LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 04-04-2012, 01:49 PM   #1
abhishekgit
Member
 
Registered: Jan 2012
Location: India
Distribution: Ubuntu, Gentoo, Fedora, Rhel5,openSUSE
Posts: 162

Rep: Reputation: 12
Hello.c in kernel 3.2.13


Hello everyone,
I have posted a similar question but not the same in LQ newbie. Sorry for re-posting but i need your help. I am compiling a hello world module in kernel 3.2.13. This is the code

Code:
#define MODULE
#include <linux/module.h>
int init_module(void) { printk("<1>Hello, world\n"); return 0; }
void cleanup_module(void) { printk("<1>Goodbye cruel world\n"); }
In the ebook I am referring its said we strongly suggest you compile and run your own kernel (without ver-
sion support) before you run the sample code.*

What does it mean?
Anyway I use this in the terminal to compile
Code:
root# gcc -c hello.c
This is the error
Code:
fatal error : linux/module.h no such file or directory.
Please help. Thanks.

Regards...
 
Old 04-04-2012, 02:54 PM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 207Reputation: 207Reputation: 207
You need to build the module within the context of the Linux kernel. To do so, you should really create a Makefile for hello.c.

With respect to that particular error, linux/module.h is a file found within the Linux kernel source / headers installtion, it does not exist in /usr/include where user-space headers are usually found.

I think you would find the most benefit from reading a document such as this:

http://www.cyberciti.biz/tips/build-...urce-tree.html
 
2 members found this post helpful.
Old 04-04-2012, 10:22 PM   #3
abhishekgit
Member
 
Registered: Jan 2012
Location: India
Distribution: Ubuntu, Gentoo, Fedora, Rhel5,openSUSE
Posts: 162

Original Poster
Rep: Reputation: 12
That helped. thanks
 
Old 04-05-2012, 02:06 PM   #4
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,358

Rep: Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106
Furthermore ... [i]virtual machine software is a wonderful thing ... that allows you to safely blow up a Linux installation without wrecking your actual system.
 
1 members found this post helpful.
Old 04-05-2012, 03:23 PM   #5
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,470

Rep: Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538
Quote:
Originally Posted by abhishekgit View Post
That helped. thanks
Yes...and that was told to you before...more than once:
https://www.linuxquestions.org/quest...efiles-933052/
https://www.linuxquestions.org/quest...071/page2.html
http://tldp.org/LDP/lkmpg/2.6/html/

Seriously, you should work on your basics first, before ATTEMPTING kernel programming. Not long ago, you asked for help in moving some files:
https://www.linuxquestions.org/quest...nation-931262/
...that's a LONG jump to compiling your own kernel.

Last edited by TB0ne; 04-05-2012 at 03:25 PM.
 
Old 04-06-2012, 02:47 AM   #6
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,490

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
Quote:
Originally Posted by abhishekgit View Post
I have posted a similar question but not the same in LQ newbie. Sorry for re-posting but i need your help.
With all the due respect, this is not a valid reason for spamming LQ with the same question! This thread now stays open, since it has been posted in the most relevant forum, but please refrain from doing that in the future. Moreover, I will not further merge your threads to avoid adding confusion. Therefore please, follow discussion here. Nuff' said.
 
Old 04-06-2012, 12:46 PM   #7
abhishekgit
Member
 
Registered: Jan 2012
Location: India
Distribution: Ubuntu, Gentoo, Fedora, Rhel5,openSUSE
Posts: 162

Original Poster
Rep: Reputation: 12
@colucix. Yes i apologize.
 
1 members found this post helpful.
Old 04-06-2012, 12:48 PM   #8
abhishekgit
Member
 
Registered: Jan 2012
Location: India
Distribution: Ubuntu, Gentoo, Fedora, Rhel5,openSUSE
Posts: 162

Original Poster
Rep: Reputation: 12
@TBOne I gave it a fortnight. I went through basic unix commands, and done shell scripting all this time. So i thought to start it
again. Anyways i ll re-consider your comment. I ll give it more time. Thanks
 
Old 04-06-2012, 03:36 PM   #9
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,470

Rep: Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538
Quote:
Originally Posted by abhishekgit View Post
@TBOne I gave it a fortnight. I went through basic unix commands, and done shell scripting all this time. So i thought to start it again. Anyways i ll re-consider your comment. I ll give it more time. Thanks
Shell scripting and basic Linux commands are still a far cry from kernel programming. And if you think you can learn enough in two weeks to be able to do it, start with learning what you've been told here.

You were pointed to the makefile and documentation. You didn't read them or follow the instructions, and didn't try to look up the error you posted here, which would have clearly told you that you didn't have the Linux source installed.
 
Old 04-07-2012, 04:03 AM   #10
abhishekgit
Member
 
Registered: Jan 2012
Location: India
Distribution: Ubuntu, Gentoo, Fedora, Rhel5,openSUSE
Posts: 162

Original Poster
Rep: Reputation: 12
@TBOne I have the source installed..3.2.13, I am reading an ebook and following the steps. I tried reading HOWTO kernel programming and README in documentation which came along with the kernel. As i mentioned, Basic concepts of unix is one of the subjects in college. I am seeking for the right direction. I need to pay attention to writing Makefiles(I think). I will give it another month. Thanks for the suggestion.
 
Old 04-07-2012, 04:16 AM   #11
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,622
Blog Entries: 29

Rep: Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896
Check out the following in the given order:
http://www.eng.hawaii.edu/Tutor/Make/
http://www.ravnborg.org/kbuild/makefiles.html

P.S.
Makefiles are Tab sensitive. If you have to start a new line
like we do in a paragraph, you need to press the Tab. Pressing
Spacebar will result in errors.

http://www.gnu.org/software/make/manual/

Last edited by TheIndependentAquarius; 04-07-2012 at 04:25 AM.
 
1 members found this post helpful.
  


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
Unable to build kernel RPM with 'custom name'. (need not kernel but kernel-something) RattleSn@ke Linux - Kernel 1 01-12-2011 06:30 PM
Config 2.6.36.1 kernel (from kernel.org) using CentOS 5.4 x86_64 kernel .config whitewolf573 Linux - Kernel 2 12-11-2010 08:33 AM
how to upgrade the Debian 3 kernel 2.4.18 to kernel 2.6 or bigmem- kernel chandu.bezawada Debian 6 11-12-2010 09:33 AM
LXer: Howto: build Linux kernel module against installed kernel w/o full kernel source tree LXer Syndicated Linux News 0 09-03-2006 08:21 PM


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