LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 12-03-2010, 09:22 PM   #1
sujeet_net29
LQ Newbie
 
Registered: Dec 2010
Posts: 3

Rep: Reputation: 0
Arrow How to compile linux device driver in Red Hat Linux-2.6.18/Fedora10


Hi I am sujeet singh, i am doing device driver programming, I wrote a program as:

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

static int init_module(void)
{
printk(KERN_INFO "Hello world\n");
return 0;
}
static void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world\n");
}

Now:question is how to compile this in fedora10 and RHEL 5.1

Last edited by sujeet_net29; 12-04-2010 at 10:13 AM. Reason: I already made make file as mentioned in three quotes
 
Old 12-04-2010, 12:03 AM   #2
mesiol
Member
 
Registered: Nov 2008
Location: Lower Saxony, Germany
Distribution: CentOS, RHEL, Solaris 10, AIX, HP-UX
Posts: 731

Rep: Reputation: 137Reputation: 137
Hi

take a look here http://www.linfo.org/create_c1.html. If you are missing compiler try
Code:
yum install gcc
.
 
Old 12-04-2010, 01:31 AM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
hello.c
Code:
#include<linux/kernel.h>
#include<linux/module.h>

int init_module(void)
{
printk(KERN_INFO "Hello world\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world\n");
}
Makefile :
Code:
 
obj-m    := hello.o

KDIR    := /lib/modules/$(shell uname -r)/build
PWD    := $(shell pwd)

default:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
The command 'make' will create 'hello.ko'.
..
 
Old 12-04-2010, 04:27 AM   #4
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
Quote:
yum install gcc
might not work on the EOL fedora 10 if too many of the mirrors have remover that unsupported and dead repo
fedora is currently at fedora 14
Quote:
Now:question is how to compile this in fedora10 and RHEL 5.1
for red hat
use the compiler in the RHN
IF THIS is a paid for rhel5
RHEL must have a paid license to install software

Code:
yum groupinstall "Development Tools" "Development Librarys"
will work on RHEL 5 ( with a license)

Last edited by John VV; 12-04-2010 at 04:28 AM.
 
Old 12-04-2010, 10:33 AM   #5
sujeet_net29
LQ Newbie
 
Registered: Dec 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for reply

But still I get problem as: module.h is not found/kernel.h is not found
 
Old 12-04-2010, 12:47 PM   #6
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Quote:
But still I get problem as: module.h is not found/kernel.h is not found
# yum install kernel-devel

Fedora and EL 5 ( + CentOS 5.5 + Scientific SL55 ) :
No errors, using the files shown in post # 3.
'make' is creating hello.ko

Solution : Install or update 'kernel-devel'.
Must be the same version as your 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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to compile device driver code for linux kernel 2.4.21 shrikantpwr245 Programming 1 06-04-2006 06:51 AM
Device driver for a USB to RS-232 Serial DB9 Adapter for red Hat 8 or 9 sp022 Linux - Hardware 1 04-18-2005 09:39 AM
Device Driver Writing Red Hat 8 & 9 unicorn21 Red Hat 2 12-14-2003 03:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 03:36 PM.

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