【发布时间】:2014-03-02 08:18:36
【问题描述】:
我知道我可以使用 makefile 中目标内的自动变量$@ 来检索当前目标的名称。现在我想知道是否有可能有一个看起来像这样的makefile:...
$@:
g++ $@ && ./a.out
这个想法是输入make test.cpp 应该运行g++ test.cpp && ./a.out 而make main.cpp 应该运行g++ main.cpp && ./a.out。
我发现通配符可能与我的问题密切相关。但是,像这样的makefile:
*.cpp:
g++ $@ && ./a.out
确实创建了适当的目标,但使用这样的 makefile 运行 make test.cpp 会产生 make: >>test.cpp<< is already up-to-date - 没有进行编译。
【问题讨论】: