获取烘焙文件中命令的输出

Getting the output of a command in a Bakefile

本文关键字:命令 输出 文件 获取      更新时间:2023-10-16

我刚刚开始使用wxWidgets进行项目,我正在尝试为跨平台编译设置一个Bakefile。我需要将wx-config --libswx-config --cxxflags的输出传递给编译器。

我怎样才能做到这一点?我在 Bakefile 文档中找不到有关将命令的输出放入变量的任何内容。反引号似乎不起作用:

myvar = `wx-config --libs`
#=> bakefile.bkl:2:12: error: no viable alternative at character u'`'

您需要在此处使用引号,即

myvar = "`wx-config --libs`"

作为参考,以下是我在自己的烘焙文件中所做的:

if ( $toolset == gnu || $toolset == gnu-osx ) {
    setting WX_CONFIG {
        default = wx-config;
        help = "Path to the wx-config script";
    }
    compiler-options += "`$(WX_CONFIG) --cppflags`";
    link-options += "`$(WX_CONFIG) --libs`";
}

这允许做一些事情,比如make WX_CONFIG=/full/path/to/wx-config,这在使用未安装的wxWidgets版本时很方便。