Windows 相当于 makefile 中的命令替换
我想在程序的“关于”框中显示当前版本号(hg 修订版)。我考虑过在代码中使用“define”(std::string rev = REVISION;)
并通过makefile将值传递给g++:
$(CPP) -c main.cpp -o main.o -DREVISION=`hg id -i`
会像魅力一样工作,但我在Windows上为Windows开发,所以我的问题:如何在Windows上创建这样的行为。
I want to display current build(hg revision) number in the about box of my program. I thought about using a "define" (std::string rev = REVISION;)
in the code and pass the value to g++ via makefile:
$(CPP) -c main.cpp -o main.o -DREVISION=`hg id -i`
would work like a charm, but im developing on windows for windows, so my Q: how to create such a behavior on windows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是 g++,那么您的假设基本上是正确的,除了传递宏定义是使用
-D
选项而不是-d
完成的。另外,Make 中的$(CPP)
通常指的是 C 预处理器。 C++ 编译器是$(CXX)
。关于命令替换,如果您在 UNIX 风格的兼容层中运行构建,它应该可以正常工作,例如 Cygwin 或 MinGW。如果没有,您可以完全避免使用命令替换,并将
hg id -i
的结果逐字传递给编译器,例如如下:If you're using g++ then your assumption is mostly right, excepting that passing a macro definition is done using
-D
option, not-d
. Also,$(CPP)
in Make usually refers to C PreProcessor. C++ compiler is$(CXX)
.Regarding command substitution, it should work fine if you run your build in UNIX-ish compatibility layer, like Cygwin or MinGW. If not, you could avoid using command substitution at all, and pass the result of
hg id -i
to the compiler literally, e.g. as follows: