LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-24-2004, 12:28 PM   #1
ssimontis
Member
 
Registered: Apr 2004
Location: USA
Distribution: Fedora Core 3
Posts: 128

Rep: Reputation: 15
Specifying C++ Header Search Paths for G++


I am working my way through the book Linux Device Drivers, 2nd Ed, and came upon a problem with the first example program, a simple module that prints "Hello World!" from the console. G++ doesn't recognize the header I used, as I believe it isn't in the search path. The header in question is linux/module.h. I need a way to see the header search path for g++, and a quick browse through info g++ didn't seem to help much. Does anyone know how to view and edit the search path for G++? Thanks in advance.
 
Old 04-24-2004, 12:32 PM   #2
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 52
Post your source code.
 
Old 04-24-2004, 01:42 PM   #3
ssimontis
Member
 
Registered: Apr 2004
Location: USA
Distribution: Fedora Core 3
Posts: 128

Original Poster
Rep: Reputation: 15
Ok. Here it is:

#define MODULE
#include <linux/module.h>

int init_module()
{
printk("<1>Hello, World!\n");
return 0;
}

void cleanup_module()
{
printk("<1>Goodbye, Cruel World!\n");
}
 
Old 04-24-2004, 01:52 PM   #4
Mohsen
Member
 
Registered: Feb 2003
Location: Iran
Distribution: Solaris 10
Posts: 201

Rep: Reputation: 30
looking at the book...
why dont you use gcc (as the book says):
Code:
root# gcc -c hello.c
root# insmod ./hello.o
Hello, world

Last edited by Mohsen; 04-24-2004 at 01:53 PM.
 
Old 04-24-2004, 02:14 PM   #5
ssimontis
Member
 
Registered: Apr 2004
Location: USA
Distribution: Fedora Core 3
Posts: 128

Original Poster
Rep: Reputation: 15
How stupid of me! I will try that and report the results.
 
Old 04-24-2004, 02:29 PM   #6
ssimontis
Member
 
Registered: Apr 2004
Location: USA
Distribution: Fedora Core 3
Posts: 128

Original Poster
Rep: Reputation: 15
Okay. I made it into a .c file and compiled it with gcc as described in the book. Now, I get a new error. Here is how it went.
gcc -c hellomodule.c
insmod ./hellomodule.o
kernel-module version mismatch
./hellomodule.o was compiled for kernel version 2.4.20
while this kernel is bersion 2.4.20-6.

I compiled this on my own machine, so what is going on?
 
Old 04-27-2004, 07:55 PM   #7
ssimontis
Member
 
Registered: Apr 2004
Location: USA
Distribution: Fedora Core 3
Posts: 128

Original Poster
Rep: Reputation: 15
Aha! I found the problem! Now my question should be, "How do I disable kernel versioning for the 2.4.20 kernel? Thanks in advance.
 
Old 11-12-2004, 10:43 AM   #8
klopex
LQ Newbie
 
Registered: Nov 2004
Location: USA
Distribution: Redhat, Mandrake
Posts: 9

Rep: Reputation: 0
Add the following to your gcc command line. It appears to fix the error for me. There will still be a warning about there being no license and therefore it might taint the kernel, but the kernel version problem seems to go away.

(You might need to put some version information after linux in the path. Search your filesystem to see what the correct path would be.)
-isystem /usr/src/linux/include

This is the command line that worked for me in the hello world module from "Linux Device Drivers" 2nd Edition. ( I defined __KERNEL__ and MODULE in the code.)
gcc -c -isystem /usr/src/linux/include hello.c
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
search default: search post title only slackie1000 LQ Suggestions & Feedback 4 03-10-2005 07:50 AM
Search results page header lhoff LQ Suggestions & Feedback 4 09-14-2004 09:09 AM
Quick VIM question (unhighlighting search terms after search) lrt2003 Linux - Newbie 5 05-08-2004 05:21 PM
c header files in linux in place of header files in windows? harun_acs Programming 1 03-17-2004 02:24 AM
Automatically resolving WINDOWS paths to pre-configured Linux paths gazzy Linux - General 1 09-05-2003 10:15 PM


All times are GMT -5. The time now is 05:25 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
Open Source Consulting | Domain Registration