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:
如何为内核模块makefile添加包含路径?我想在test_module.c中包含“test_kernel.h”。 “test_kernel.h”驻留在其他目录“inc”中我在Makefile中的以下解决方案中尝试但是它不起作用:
obj-m += test_module.o
test_module:
$(MAKE) -C "$(LINUX_DIR)" -Iinc $(MAKE_OPTS) modules
3 个解决方案
#1
12
You should make use of EXTRA_CFLAGS
in your Makefile
. Try something on these lines:
您应该在Makefile中使用EXTRA_CFLAGS。尝试这些方面的东西:
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!
请参见此处的3.7编译标志部分。希望这可以帮助!
#2
0
-I
is a GCC flag, not a Make flag.1 You need to pass a variable down to your "sub" Make process; perhaps something like this:
-I是GCC标志,而不是Make标志.1你需要将一个变量传递给你的“sub”Make过程;也许是这样的:
$(MAKE) -C "$(LINUX_DIR)" CPPFLAGS="-Iinc" $(MAKE_OPTS) modules
where CPPFLAGS
is a standard Make variable that's used in the implicit rules. Feel free to use your own variable instead, and ensure it's used appropriately in the sub-make.
其中CPPFLAGS是隐式规则中使用的标准Make变量。您可以随意使用自己的变量,并确保在子制作中使用它。
The Make manual gives more details on communicating variables between Make instances: http://www.gnu.org/software/make/manual/make.html#Variables_002fRecursion.
Make手册提供了有关在Make实例之间传递变量的更多详细信息:http://www.gnu.org/software/make/manual/make.html#Variables_002fRecursion。
1. Actually, it is also a Make flag, but for something completely unrelated.
#3
0
are you sure you correctly specified the include in your file?
你确定你在文件中正确指定了include吗?
e.g.:
#include "inc/something.h"
instead of
#include <inc/something.h>
#1
12
You should make use of EXTRA_CFLAGS
in your Makefile
. Try something on these lines:
您应该在Makefile中使用EXTRA_CFLAGS。尝试这些方面的东西:
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!
请参见此处的3.7编译标志部分。希望这可以帮助!
#2
0
-I
is a GCC flag, not a Make flag.1 You need to pass a variable down to your "sub" Make process; perhaps something like this:
-I是GCC标志,而不是Make标志.1你需要将一个变量传递给你的“sub”Make过程;也许是这样的:
$(MAKE) -C "$(LINUX_DIR)" CPPFLAGS="-Iinc" $(MAKE_OPTS) modules
where CPPFLAGS
is a standard Make variable that's used in the implicit rules. Feel free to use your own variable instead, and ensure it's used appropriately in the sub-make.
其中CPPFLAGS是隐式规则中使用的标准Make变量。您可以随意使用自己的变量,并确保在子制作中使用它。
The Make manual gives more details on communicating variables between Make instances: http://www.gnu.org/software/make/manual/make.html#Variables_002fRecursion.
Make手册提供了有关在Make实例之间传递变量的更多详细信息:http://www.gnu.org/software/make/manual/make.html#Variables_002fRecursion。
1. Actually, it is also a Make flag, but for something completely unrelated.
#3
0
are you sure you correctly specified the include in your file?
你确定你在文件中正确指定了include吗?
e.g.:
#include "inc/something.h"
instead of
#include <inc/something.h>