Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > The Linux Kernel > GCC and Kernel Development [compile help]

Forgot Password?
 The Linux Kernel   Compiling, theory, programming or other discussion about the linux kernel

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 09-28-2009   #1 (permalink)
Just Joined!
 
Join Date: Jul 2008
Posts: 12
Send a message via Yahoo to hapster
GCC and Kernel Development [compile help]

Hi

How do I compile c source code using gcc so that it would produce .ko objects for kernel module development? I'm trying to use Eclipse to manage development projects but can't use the build feature just yet since I don't know what to put in.

Thanks.
hapster is offline  


Reply With Quote
Old 09-28-2009   #2 (permalink)
Linux Guru
 
coopstah13's Avatar
 
Join Date: Nov 2007
Location: NH, USA
Posts: 1,756
does eclipse even support a C IDE? if you want to do kernel development you will need to install the linux-headers and build-essential packages, I think it would be
Code:
sudo apt-get install build-essential linux-headers-`uname -r`
if you are looking for how to do kernel module development, I would start here: Linux Device Drivers, Third Edition [LWN.net]
coopstah13 is offline   Reply With Quote
Old 09-29-2009   #3 (permalink)
Just Joined!
 
Join Date: Jul 2008
Posts: 12
Send a message via Yahoo to hapster
re

Quote:
Originally Posted by coopstah13 View Post
does eclipse even support a C IDE? if you want to do kernel development you will need to install the linux-headers and build-essential packages, I think it would be
Code:
sudo apt-get install build-essential linux-headers-`uname -r`
Eclipse has CDT (C/C++ Development Tools) and I've already done some C/C++ projects using it. I don't know how to set it up to automate the building of kernel modules from C source code. I usually do it by manually creating the Makefiles as stated in tutorials. If I can use the gcc command (with corresponding options) than I can set it up in Eclipse.
hapster is offline   Reply With Quote
Old 09-29-2009   #4 (permalink)
Linux Guru
 
coopstah13's Avatar
 
Join Date: Nov 2007
Location: NH, USA
Posts: 1,756
So you just need to know how to create a make file that will build a kernel module? You want to generate this makefile automatically or manually? The link in my previous post will show you how to create a make file that will compile a kernel module. If you need to automate this, you will need to look into using some kind of configure script, I'm sure there are many tutorials you can find on configure scripts by searching google.
coopstah13 is offline   Reply With Quote
Old 09-29-2009   #5 (permalink)
Just Joined!
 
Join Date: Jul 2008
Posts: 12
Send a message via Yahoo to hapster
Quote:
Originally Posted by coopstah13 View Post
So you just need to know how to create a make file that will build a kernel module? You want to generate this makefile automatically or manually? The link in my previous post will show you how to create a make file that will compile a kernel module. If you need to automate this, you will need to look into using some kind of configure script, I'm sure there are many tutorials you can find on configure scripts by searching google.
I tried compiling two .c files using the Makefile found in the Linux Device Drivers book. However it always fails. I can only compile one file and it should have the same name as the driver I'm compiling.
hapster is offline   Reply With Quote
Old 09-29-2009   #6 (permalink)
Just Joined!
 
Join Date: Jul 2008
Posts: 12
Send a message via Yahoo to hapster
Quote:
Originally Posted by coopstah13 View Post
So you just need to know how to create a make file that will build a kernel module? You want to generate this makefile automatically or manually? The link in my previous post will show you how to create a make file that will compile a kernel module. If you need to automate this, you will need to look into using some kind of configure script, I'm sure there are many tutorials you can find on configure scripts by searching google.
I got the makefile working but I couldn't compile 2 or more source codes.

I have 2 files named nothing.c and hello.c

Here's my current makefile:
Code:
obj-m := test.o
module-objs := nothing.o hello.o

default:
	make -C /lib/modules/`uname -r`/build M=`pwd` modules
I wanted to produce a kernel module named test.ko but it produces this error:
make -C /lib/modules/`uname -r`/build M=`pwd` modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.28-15-generic'
make[2]: *** No rule to make target `/home/rba1988/Desktop/test.c', needed by `/home/rba1988/Desktop/test.o'. Stop.
make[1]: *** [_module_/home/rba1988/Desktop] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.28-15-generic'
make: *** [default] Error 2
hapster is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 06:19 AM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2