在一个生成文件中生成多个生成

Generate multiple builds in one makefile

本文关键字:文件 一个      更新时间:2023-10-16

每次运行make时,我都想让我的单元测试与我的项目一起构建。我尝试在我的Makefile中使用以下代码来做到这一点:

DEPS = Parallel.cpp Resistor.cpp Series.cpp Source.cpp
TEST = Parallel.cpp Resistor.cpp Series.cpp Test.cpp
resistor: $(DEPS)
        g++ -std=c++11 -o resistor $(DEPS) -I. -g
test: $(TEST)
        g++ -std=c++11 -o test $(TEST) -I. -g

然而,当我查看目录时,我只看到了/电阻器而不是/测验顺便说一句,任何以其他方式改进我的makefile的建议都是受欢迎的。

您可以添加以下规则作为Makefile:中的第一条规则

all: resistor test

然后运行make:

$ make
g++ -std=c++11 -o resistor Parallel.cpp Resistor.cpp Series.cpp Source.cpp -I. -g
g++ -std=c++11 -o test Parallel.cpp Resistor.cpp Series.cpp Test.cpp -I. -g

根据make文件:

默认情况下,make以第一个目标(而不是其名称以"."开头)。