how to add an include path - Linux

This is a discussion on how to add an include path - Linux ; 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 ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: how to add an include path

  1. 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!

  2. Re: how to add an include path

    bz800k@hotmail.com wrote:
    > Is it possible to add an arbitrary include directory to include
    > search path?


    Read the manual for your compiler.

    With most compilers you need the -I option.

    HTH,
    - J.

  3. Re: how to add an include path

    bz800k@hotmail.com wrote:
    > 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!


    How about specifying the full pathname with EXTRA_CFLAGS += -I ?

  4. Re: how to add an include path

    bz800k@hotmail.com wrote in news:74e6b360-5382-4216-8c93-0b23c6cc79f2
    @p10g2000prf.googlegroups.com:

    > 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?


    EXTRA_CFLAGS should work. This works for me (hello.c modified to
    include 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

  5. 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!!!!!

+ Reply to Thread