C++ 使用 Makefile 在编译中排除源文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10276202/
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
Exclude source file in compilation using Makefile
提问by domlao
Is it possible to exclude a source file in the compilation process using wildcard function in a Makefile?
是否可以在 Makefile 中使用通配符函数在编译过程中排除源文件?
Like have several source files,
就像有几个源文件一样,
src/foo.cpp
src/bar.cpp
src/...
Then in my makefile I have,
然后在我的makefile中,
SRC_FILES = $(wildcard src/*.cpp)
But I want to exclude the bar.cpp. Is this possible?
但我想排除 bar.cpp。这可能吗?
回答by Beta
If you're using GNU Make, you can use filter-out
:
如果您使用的是 GNU Make,则可以使用filter-out
:
SRC_FILES := $(wildcard src/*.cpp)
SRC_FILES := $(filter-out src/bar.cpp, $(SRC_FILES))
Or as one line:
或者作为一行:
SRC_FILES = $(filter-out src/bar.cpp, $(wildcard src/*.cpp))
回答by K1773R
use find for it :)
使用 find :)
SRC_FILES := $(shell find src/ ! -name "bar.cpp" -name "*.cpp")
回答by Dmitri Chubarov
You can use Makefile subst function:
您可以使用 Makefile subst 函数:
EXCLUDE=$(subst src/bar.cpp,,${SRC_FILES})
回答by ma11hew28
The Unix globpattern src/[!b]*.cpp excludes all src files that start with b.
在Unix的水珠图案的src / [!B] *。CPP排除以b开头的SRC文件。
That only would work, however, if bar.cpp is the only src file that starts with b or if you're willing to rename it to start with a unique character.
但是,只有当 bar.cpp 是唯一以 b 开头的 src 文件或者您愿意将其重命名为以唯一字符开头时,这才有效。