how to add an include path
Hi,
I'm making a sample module in linux2.6.
Makefile is as follows.
-----------------------------------------------
ifneq ($(KERNELRELEASE),)
obj-m := sample.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
-----------------------------------------------
sample.c includes a file in a other directory.
I tried to add the include directory by
CFLAGS, EXTRA_CFLAGS, CPPFLAGS, INCLUDES,
KERNEL_INCLUDE,...., but it failed.
Is it possible to add an arbitrary include directory to include
search path?
Thanks!
Re: how to add an include path
[email]bz800k@hotmail.com[/email] wrote:[color=blue]
> Is it possible to add an arbitrary include directory to include
> search path?[/color]
Read the manual for your compiler.
With most compilers you need the -I option.
HTH,
- J.
Re: how to add an include path
[email]bz800k@hotmail.com[/email] wrote:[color=blue]
> Hi,
>
> I'm making a sample module in linux2.6.
> Makefile is as follows.
>
> -----------------------------------------------
> ifneq ($(KERNELRELEASE),)
> obj-m := sample.o
> else
> KERNELDIR ?= /lib/modules/$(shell uname -r)/build
> PWD := $(shell pwd)
>
> default:
> $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
>
> endif
> -----------------------------------------------
>
> sample.c includes a file in a other directory.
>
> I tried to add the include directory by
> CFLAGS, EXTRA_CFLAGS, CPPFLAGS, INCLUDES,
> KERNEL_INCLUDE,...., but it failed.
>
> Is it possible to add an arbitrary include directory to include
> search path?
> Thanks![/color]
How about specifying the full pathname with EXTRA_CFLAGS += -I <full pathname> ?
Re: how to add an include path
[email]bz800k@hotmail.com[/email] wrote in news:74e6b360-5382-4216-8c93-0b23c6cc79f2
@p10g2000prf.googlegroups.com:
[color=blue]
> default:
> $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
>
> endif
> sample.c includes a file in a other directory.
>
> I tried to add the include directory by
> CFLAGS, EXTRA_CFLAGS, CPPFLAGS, INCLUDES,
> KERNEL_INCLUDE,...., but it failed.
>
> Is it possible to add an arbitrary include directory to include
> search path?[/color]
EXTRA_CFLAGS should work. This works for me (hello.c modified to
include <foo.h> which exists in /tmp/inc):
obj-m := hello.o
KERNELDIR ?= /usr/src/linux
EXTRA_CFLAGS = -I/tmp/inc
all:
$(MAKE) -C $(KERNELDIR) M=$(shell pwd) modules
Bear in mind that when the compiler is run, the current directory will
be KERNELDIR *not* the directory where your module source exists.
Furthermore, your makefile is evaluated recursively so using a relative
path name like "EXTRA_CFLAGS=-I$(shell pwd)/../inc" won't work unless
appropriately protected. This does work though:
ifndef EXTRA_CFLAGS
export EXTRA_CFLAGS = -I$(shell pwd)/../inc
endif
If still not working for you, try running "make -n" and see if that
helps diagnose.
GH
Re: how to add an include path
Hi,
Thank you for all of you!
I was troubled for days...
Yes, I specified a include directory as relative path.....
I tried again with full path name, then compiling succeeded!!
EXTRA_CFLAGS worked correctly
and
"ifndef EXTRA_CFLAGS
export EXTRA_CFLAGS = -I$(shell pwd)/../inc
endif" also worked!!
Thanks!!!!!