LinuxQuestions.org
Help answer threads with 0 replies.
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 03-18-2009, 02:40 PM   #1
netskink
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Rep: Reputation: 0
how to create a driver makefile which uses header files outside current dir?


Hi

I want to build a driver for the linux kernel which uses header files not in the current directory.

== Dir tree looks like this

/foo/inc/myheader.h
/foo/driver/mydriver.c
/foo/driver/Makefile

== /driver/Makefile looks like this:

KERNELDIR=/usr/src/linux
TOPDIR=/foo
obj-m := mydriver.o

mydriver.o: mydriver.c ../inc/myheader.h
$(MAKE) -I $(TOPDIR)/inc -C $(KERNELDIR) M=`pwd` modules

== This will work until I add the following line in mydriver.c

#include <myheader.h>

At that point, it will complain that it can not find myheader.h

During compile, I see this:

make - I /foo/inc -C /usr/src/linux M=`pwd` modules
make [3] Entering Directory `/usr/src/linux'
CC [M] /foo/driver/mydriver.o
/foo/driver/mydriver.c:20:10: error: myheader.h: No such filer or directory
 
Old 03-18-2009, 02:51 PM   #2
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
#include "inc/myheader.h"

Using <myheader.h> tells the compiler to look for the include in the standard include path. Putting it in quotes instead specifies a search relative to the directory you are compiling in.
 
Old 03-18-2009, 03:31 PM   #3
netskink
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Original Poster
Rep: Reputation: 0
outside current dir?

#include "foo.h" does not work.
#include "inc/foo.h" also does not work.
 
Old 03-20-2009, 01:54 PM   #4
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
Suggest : Move or copy 'myheader.h' to foo/driver/ ,
then it will sit in the same directory as 'mydriver.c'
and can be included with : #include "myheader.h"

" " is for a local file, < > is for a system file,
e.g. in /usr/include/ .

.....
 
Old 05-11-2009, 04:06 AM   #5
antiregulator
LQ Newbie
 
Registered: Apr 2009
Posts: 13

Rep: Reputation: 0
i can't exactly provide you with a solution, because i'm looking in to these matters myself this time, still i think that if you haven't already looked there, there's some documentation at /usr/src/linux-`uname -r`/Documentation/kbuild/modules.txt

specially chapter 6 on include directories

Last edited by antiregulator; 05-11-2009 at 04:08 AM.
 
Old 05-21-2009, 10:35 AM   #6
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 227

Rep: Reputation: 32
#include "../inc/foo.h" -> it will work
 
  


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 create header files in unix? nid_ice@yahoo.co.in Programming 2 06-29-2005 11:21 PM
How to write Makefile in 2.6 for including header files in another dir ? ashbalu Programming 0 10-19-2004 03:45 PM
Creating a Makefile with multiple header files MattG1981 Programming 4 07-28-2004 05:04 PM
[makefile] Do header files need to be set targets? chuanyung Programming 2 03-11-2004 09:22 PM
location of dir of C header files? VMWARE install.. s7nner Linux - Newbie 3 09-07-2003 11:32 PM

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

All times are GMT -5. The time now is 07:54 AM.

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