Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Linux - Kernel This forum is for all discussion relating to the Linux kernel.


  Search this Thread
Old 03-18-2009, 03:40 PM   #1
LQ Newbie
Registered: Mar 2009
Posts: 2

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


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

== Dir tree looks like this


== /driver/Makefile looks like this:

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, 03:51 PM   #2
Senior Member
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
#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, 04:31 PM   #3
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, 02:54 PM   #4
LQ 5k Club
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2017 CentOS6.9 CentOS7.4 + 50+ other Linux OS, for test only.
Posts: 16,755

Rep: Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329
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, 05:06 AM   #5
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 05:08 AM.
Old 05-21-2009, 11:35 AM   #6
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 220

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


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

All times are GMT -5. The time now is 09:24 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration