Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > Linux
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Linux General discussion of programming the various flavors of Linux operating systems.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Linux section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 5th, 2005, 05:15 AM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Begin Linux Prog - Drivers -Errors

Hi, new here, and having trouble with hello.c compliling.
I am using Fedora Core 2, and I am trying to compile hello.c in chapter 18 of the book Beginning Linux Programming 3rd edition!

Thanks for the great book. Hope to be on this site to pick more brains!

Here is the output from the screen. I modified the directories to work with my setup, only where the h files are located.

Thanks for the help.

[root@PositekVoice hfc]# gcc -D__KERNEL__ -I/usr/src/linux-2.6.5-1.358/include/linux -DMODULE -Wall -O2 -c hello.c -o hello.o
In file included from /usr/src/linux-2.6.5-1.358/include/linux/module.h:9,
                 from hello.c:4:
/usr/include/linux/config.h:5:2: #error Incorrectly using glibc headers for a kernel module
In file included from /usr/include/linux/sched.h:14,
                 from /usr/src/linux-2.6.5-1.358/include/linux/module.h:10,
                 from hello.c:4:
/usr/include/linux/timex.h:148: error: field `time' has incomplete type
In file included from /usr/include/linux/signal.h:4,
                 from /usr/include/linux/sched.h:25,
                 from /usr/src/linux-2.6.5-1.358/include/linux/module.h:10,
                 from hello.c:4:
/usr/include/asm/signal.h:107: error: syntax error before "sigset_t"
/usr/include/asm/signal.h:110: error: syntax error before '}' token
In file included from hello.c:4:
/usr/src/linux-2.6.5-1.358/include/linux/module.h:15:25: linux/cache.h: No such file or directory
/usr/src/linux-2.6.5-1.358/include/linux/module.h:16:24: linux/kmod.h: No such file or directory
/usr/src/linux-2.6.5-1.358/include/linux/module.h:18:29: linux/stringify.h: No such file or directory
/usr/src/linux-2.6.5-1.358/include/linux/module.h:19:23: asm/local.h: No such file or directory
In file included from /usr/src/linux-2.6.5-1.358/include/linux/module.h:21,
                 from hello.c:4:
/usr/include/asm/module.h:4:2: warning: #warning Using kernel headers in userspace!
In file included from hello.c:4:
/usr/src/linux-2.6.5-1.358/include/linux/module.h:500: error: syntax error before "MOD_INC_USE_COUNT"
/usr/src/linux-2.6.5-1.358/include/linux/module.h:501: warning: return type defaults to `int'
/usr/src/linux-2.6.5-1.358/include/linux/module.h:512: error: syntax error before "MOD_DEC_USE_COUNT"
/usr/src/linux-2.6.5-1.358/include/linux/module.h:513: warning: return type defaults to `int'
hello.c: In function `init_module':
hello.c:19: warning: implicit declaration of function `printk'
hello.c:19: error: `KERN_DEBUG' undeclared (first use in this function)
hello.c:19: error: (Each undeclared identifier is reported only once
hello.c:19: error: for each function it appears in.)
hello.c:19: error: syntax error before string constant
hello.c: In function `cleanup_module':
hello.c:25: error: `KERN_DEBUG' undeclared (first use in this function)
hello.c:25: error: syntax error before string constant
[root@PositekVoice hfc]# cat hello.c
Reply With Quote
  #2 (permalink)  
Old June 6th, 2005, 05:15 PM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Finaly got module to compile. Major changes to the way that Linux compiles modules came out around Linux 2.5.

Thanks.:D
Reply With Quote
  #3 (permalink)  
Old September 20th, 2005, 08:19 PM
Registered User
 
Join Date: Sep 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, I'm just starting Linux programming at school, and I'm having a very similar problem at home.

I have a hello.c program that is
--------------------------------------------------
#include <linux/module.h>
#include <linux/kernel.h>

int init_module(void){
  printk(KERN_INFO "Hello World!\n");
  return 0;
}

void cleanup_module(void){
  printk(KERN_INFO "Goodbye\n");
}
--------------------------------------------------
I have a Makefile that is:

CC=gcc

CFLAGS = -D__KERNEL__ -DMODULE -02

hello.o: hello.c
        ${CC} ${CFLAGS} -c hello.c

myzero_nrw.o: myzero_nrw.c
        ${CC} ${CFLAGS} -c myzero_nrw.c
        #insmod myzero_nrw.o to turn it on
        #rmmod myzero_nrw.o to turn it off

bufdev.o: bufdev.c
        ${CC} ${CFLAGS} -c bufdev.c
        #insmod bufdev.o to turn it on
        #rmmod bufdev to trun it off

seriali.o: seriali.c
        ${CC} ${CFLAGS} -c seriali.c
        #insmod seriali.o major=num to turn it on
        #rmmod seriali to trun it off

clean:
        rm -f *.o a.out core
-----------------------------------------------
and the error I'm getting is this:

[root@localhost ass1]# make hello.o
gcc -D__KERNEL__ -DMODULE -02 -c hello.c
gcc: unrecognized option '-02'
In file included from /usr/include/linux/module.h:10,
                 from hello.c:1:
/usr/include/linux/config.h:5:2: error: #error Incorrectly using glibc headers for a kernel module
hello.c: In function ‘init_module’:
hello.c:5: error: ‘KERN_INFO’ undeclared (first use in this function)
hello.c:5: error: (Each undeclared identifier is reported only once
hello.c:5: error: for each function it appears in.)
hello.c:5: error: syntax error before string constant
hello.c: In function ‘cleanup_module’:
hello.c:10: error: ‘KERN_INFO’ undeclared (first use in this function)
hello.c:10: error: syntax error before string constant
make: *** [hello.o] Error 1
[root@localhost ass1]#



any ideas on how to fix this would be greatly appreciated. Thanks

I'm running Linux 2.6.11-1.1369_FC4 #1 Thu Jun 2 22:55:56 EDT 2005 i686 i686 i386 GNU/Linux


Reply With Quote
  #4 (permalink)  
Old October 18th, 2005, 06:40 PM
Registered User
 
Join Date: Oct 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Were you able to come to a resolution on this as I am now encountering the same error

Reply With Quote
Reply


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux kernel configuration to include SCSI drivers manitu Linux 0 August 9th, 2005 11:40 AM
Begin VB.NET Ch12 - Registry CLLinder BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 August 5th, 2005 04:29 AM
How to generate weeknumber/begin of week date in method Access 2 June 22nd, 2005 11:13 AM
where should i begin from wenliang C++ Programming 1 September 18th, 2003 07:51 PM



All times are GMT -4. The time now is 02:41 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.