![](/img/trans.png)
[英]Is it possible to use gcc/g++/nvcc automatic dependency -M in a single pass of a Makefile without saving dependencies to a file?
[英]Makefile with multiple targets and automatic dependency generation using g++ -MMD
SO上的另一个问题描述了单个目标的完美优雅的makefile:
CXX = g++ # compiler
CXXFLAGS = -g -Wall -MMD # compiler flags
OBJECTS = x.o y.o z.o # object files forming executable
DEPENDS = ${OBJECTS:.o=.d} # substitutes ".o" with ".d"
EXEC = a.out # executable name
${EXEC} : ${OBJECTS} # link step
${CXX} ${OBJECTS} -o ${EXEC}
-include ${DEPENDS} # copies files x.d, y.d, z.d (if they exist)
我的问题是:我们如何才能针对多个目标进行调整?
您的解决方案看起来不错,但是如果目标很多,那么扩展起来就容易一点:
EXECS = exec_x exec_y
exec_x: a.o b.o c.o
exec_y: d.o e.o f.o
$(EXECS):
${LINK}
我找到了一个可行的解决方案,但我很想知道这是否合适。
CXX = g++ # compiler
CXXFLAGS = -g -Wall -MMD # compiler flags
LINK = ${CXX} $^ -o $@ # link step
exec_x: a.o b.o c.o
${LINK}
exec_y: d.o e.o f.o
${LINK}
-include *.d
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.