Windows 相当于 makefile 中的命令替换

发布于 2024-12-25 02:36:30 字数 258 浏览 3 评论 0原文

我想在程序的“关于”框中显示当前版本号(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

呆° 2025-01-01 02:36:30

如果您使用的是 g++,那么您的假设基本上是正确的,除了传递宏定义是使用 -D 选项而不是 -d 完成的。另外,Make 中的$(CPP) 通常指的是 C 预处理器。 C++ 编译器是$(CXX)

    $(CXX) -c main.cpp -o main.o -DREVISION=`hg id -i`

关于命令替换,如果您在 UNIX 风格的兼容层中运行构建,它应该可以正常工作,例如 CygwinMinGW。如果没有,您可以完全避免使用命令替换,并将 hg id -i 的结果逐字传递给编译器,例如如下:

REVISION := $(shell hg id -i)

...
    $(CXX) -c main.cpp -o main.o -DREVISION=$(REVISION)

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).

    $(CXX) -c main.cpp -o main.o -DREVISION=`hg id -i`

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:

REVISION := $(shell hg id -i)

...
    $(CXX) -c main.cpp -o main.o -DREVISION=$(REVISION)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文