gpt4 book ai didi

c++ - 在一个 makefile 中生成多个构建

转载 作者:行者123 更新时间:2023-11-30 02:31:57 25 4
gpt4 key购买 nike

每次运行 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

然而,当我查看目录时,我只看到 ./resistor 而不是 ./test.... 顺便说一句,欢迎任何以其他方式改进我的 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

根据 the make documentation :

By default, make starts with the first target (not targets whose names start with ‘.’).

关于c++ - 在一个 makefile 中生成多个构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36972053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com