LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 06-11-2002, 12:57 PM   #1
johnvoisey
Member
 
Registered: Jun 2002
Location: UK
Distribution: Used many over the years, main ones now "CentOS", Slackware and Arch
Posts: 31

Rep: Reputation: 15
Question Problem compiling demonstration module using 2.4.18


For various reasons too boring to go into in detail I have been reading up on writing linux kernel modules, and I figured a good place to start was the "lkmpg" (linux kernel module programming guide" on the linux documentation project.

Now I know just about enough 'c' to be a danger to myself and others (where have I heard that before !!!) but I reckoned that even I could follow the examples in a linux documentaion project guide and get somewhere, yeah ?

Wrong. I'm a miserable failure. I can't even get past creating the module of "hello, world !!" I followed the details in the guide to the letter, created the example hello.c, created the Makefile, and then ran make.

it came back with a complaint that there was a "parse error before 'size_t'" in lines 73 and 75 of /usr/include/linux/kernel.h before whingeing about an implicit definition of print_k and a final [Error 1]

I've spent a day now poking round other modules, google and FAQS till I've got 'C' code burned into my retinas.

My best guess is that I need some other header files in front of the #include <linux/kernel.h> in order to provide the definition of "size_t". However I have no idea which ones they might be.
I have looked round the linux source tree for some inspiration, but just became more and more confused as I dug deeper !

I'm running a Slackware 8.0 distribution (downloaded as ISOS) buit I have upgraded the linux kernel source to 2.4.18 and modutils to 2.4.16 because that was supposed to have fixed problems with the new firewall code and also is said to support the Belkin Direct Connect USB networking cable.

My gcc version is 2.95.3

If I need to supply more details to pin this down, please tell me what I need to specify.

Any assistance greatly appreciated
 
Old 06-14-2002, 03:14 AM   #2
johnvoisey
Member
 
Registered: Jun 2002
Location: UK
Distribution: Used many over the years, main ones now "CentOS", Slackware and Arch
Posts: 31

Original Poster
Rep: Reputation: 15
Well, I found an answer to this, although i do not (yet) fully understand what is going on. It makes me feel a bit stupid owning up to this, but I see from a google search that there are others with the same problem, who have not yet received an answer.

First thing to say is that if you take the standard example code and example makefile as shown in Ori Pomerantz's lkmpg document, and try that against a linux box running a 2.2.19 kernel and the 2.2.19 source tree on the slackware 8.0 distrib, IT WORKS. It whinges a bit with warnings out of gcc 2.95.3 but it does work. Do the same against a 2.4.5 kernel and source and it ALSO works, this time without whingeing. So IMHO it HAD to be something in the gcc flags for the makefile.

I went back to basics on a 2.4.18 system, rebuilt a kernel for the sheer hell of it and captured the output at the "make modules" stage. "make modules > my_logfile 2>&1" did the trick

I then took a HARD look at how the makefile made the dummy.o module in /usr/src/linux/drivers/net. This dummy module was, I reckoned, a good candidate for scrutiny as it is not much more than a skeleton driver. From the make modules logfile, I saw the command line to gcc was huge compared to the one used in the lkmpg demo.

I cut and pasted every gcc flag into the lkmpg demo makefile and once I had done so, the hello, world module compiled !!!!

The makefile I used now looks like this

#Makefile for Ori Pomerantz lkmpg, 2.4.18 kernel version
#Author: John Voisey. Use at Own Risk !!!
cc=gcc
MODCFLAGS := -D__KERNEL__ \
-I/usr/src/linux-2.4.18/include -Wall \
-Wstrict-prototypes -Wno-trigraphs -O2 \
-fomit-frame-pointer -fno-strict-aliasing \
-fno-common -pipe -mpreferred-stack-boundary=2 \
-march=k6 -DMODULE -DMODVERSIONS \
-include /usr/src/linux-2.4.18/include/linux/modversions.h -DKBUILD_BASENAME=hello

hello.o: hello.c /usr/include/linux/version.h
$(CC) $(MODCFLAGS) -c hello.c
echo insmod hello.o to turn it on
echo rmmod hello to turn it off


I hope this helps anyone in the same predicament as me !!
 
  


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
problem with compiling a simple module pele21 Linux - Software 2 04-28-2005 02:29 AM
compiling via-rhine module problem aherrys Slackware 0 11-27-2004 11:01 PM
fglrx compiling custom module problem (firegl_public.c) Slate01 Linux - Hardware 0 11-25-2004 02:25 PM
compiling a kernel: module-init-tools conflict, depmod problem, modules sterrenkijker Debian 3 03-08-2004 10:07 PM
Problem with compiling module under slackware Altos Programming 0 02-22-2003 12:46 PM


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

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