C++ 如何在Makefile中定义几个包含路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4134764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to define several include path in Makefile
提问by groovehunter
New to C++; Basic understanding of includes, libraries and the compile process. Did a few simple makefiles yet.
C++ 新手;对包含、库和编译过程的基本理解。还做了一些简单的makefile。
My current project involves using an informix DB api and i need to include header files in more than one nonstandard dirs. How to write that ? Havent found anything on the net, probably because i did not use good search terms
我当前的项目涉及使用一个 informix DB api,我需要在多个非标准目录中包含头文件。那怎么写?网上没找到,可能是因为我没有使用好的搜索词
This is one way what i tried (not working). Just to show the makefile
这是我尝试过的一种方式(不起作用)。只是为了显示makefile
LIB=-L/usr/informix/lib/c++
INC=-I/usr/informix/incl/c++ /opt/informix/incl/public
default: main
main: test.cpp
gcc -Wall $(LIB) $(INC) -c test.cpp
#gcc -Wall $(LIB) $(INC) -I/opt/informix/incl/public -c test.cpp
clean:
rm -r test.o make.out
回答by Antoine Pelisse
You have to prepend every directory with -I
:
您必须在每个目录前加上-I
:
INC=-I/usr/informix/incl/c++ -I/opt/informix/incl/public
回答by wilhelmtell
You need to use -I
with each directory. But you can still delimit the directories with whitespace if you use (GNU) make's foreach
:
您需要-I
与每个目录一起使用。但是,如果您使用 (GNU) make's ,您仍然可以用空格分隔目录foreach
:
INC=$(DIR1) $(DIR2) ...
INC_PARAMS=$(foreach d, $(INC), -I$d)