How do I add an include path for kernel module makefile

c, linux-kernel, makefile

Solution

You should make use of `EXTRA_CFLAGS` in your `Makefile`. Try something on these lines:

obj-m += test_module.o
EXTRA_CFLAGS=-I$(PWD)/inc

test_module:
    $(MAKE) -C "$(LINUX_DIR)" $(MAKE_OPTS) modules

See section 3.7 `Compilation Flags` section here. Hope this helps!

Problem

How do I add an include path for kernel module makefile? I want to include "test_kernel.h" in test_module.c. the "test_kernel.h" resides in other directory "inc" I tried in the following solution in my Makefile but it does not work: ``` obj-m += test_module.o test_module: $(MAKE) -C "$(LINUX_DIR)" -Iinc $(MAKE_OPTS) modules ```

Original source