Boost spirit调试输出没有出现

Boost spirit debug output does not appear

我正在尝试 this question 的第二个答案。解析本身工作正常,但在第一行取消注释 #define BOOST_SPIRIT_DEBUG 后,BOOST_SPIRIT_DEBUG 输出仍然没有出现在任何地方。

当我将下面的这 3 行添加到 main() 时,我看到所有 3 行都出现在我的终端中。但是,我没有看到任何解析器调试行。缺少什么?

std::cout << "Hello cout" << std::endl;
std::cerr << "Hello cerr" << std::endl;
BOOST_SPIRIT_DEBUG_OUT << "Hello boost spirit debug out" << std::endl;

可能值得一提我正在使用 Qt Creator。

我无法重现:

Live On Coliru

#define BOOST_SPIRIT_DEBUG
#include <boost/spirit/include/qi.hpp>

int main() {
    std::cout << "Hello cout" << std::endl;
    std::cerr << "Hello cerr" << std::endl;
    BOOST_SPIRIT_DEBUG_OUT << "Hello boost spirit debug out" << std::endl;
}

版画

Hello cout
Hello cerr
Hello boost spirit debug out

所以所有常见的罪魁祸首是:

  • 构建过时
  • 运行 与构建的二进制文件不同的二进制文件
  • 预编译 header毁了你的一天?当您在预编译 header 包含之前包含任何内容时,[在我知道的任何编译器中] 都会导致警告,但请注意以防万一。

这是链接的第二个答案演示 Live On Coliru with debug output (or without):

<expr_>
  <try>-99</try>
  <function_call_>
    <try>-99</try>
    <fail/>
  </function_call_>
  <value_>
    <try>-99</try>
    <success></success>
    <attributes>[-99]</attributes>
  </value_>
  <success></success>
  <attributes>[-99]</attributes>
</expr_>
input:  -99
eval:   -99

<expr_>
  <try>'string'</try>
  <function_call_>
    <try>'string'</try>
    <fail/>
  </function_call_>
  <value_>
    <try>'string'</try>
    <string_>
      <try>'string'</try>
      <success></success>
      <attributes>[[s, t, r, i, n, g]]</attributes>
    </string_>
    <success></success>
    <attributes>[[s, t, r, i, n, g]]</attributes>
  </value_>
  <success></success>
  <attributes>[[s, t, r, i, n, g]]</attributes>
</expr_>
input:  'string'
eval:   string

<expr_>
  <try>AnswerToLTUAE()</try>
  <function_call_>
    <try>AnswerToLTUAE()</try>
    <success></success>
    <attributes>[42]</attributes>
  </function_call_>
  <success></success>
  <attributes>[42]</attributes>
</expr_>
input:  AnswerToLTUAE()
eval:   42

<expr_>
  <try>ReverseString('strin</try>
  <function_call_>
    <try>ReverseString('strin</try>
    <expr_>
      <try>'string')</try>
      <function_call_>
        <try>'string')</try>
        <fail/>
      </function_call_>
      <value_>
        <try>'string')</try>
        <string_>
          <try>'string')</try>
          <success>)</success>
          <attributes>[[s, t, r, i, n, g]]</attributes>
        </string_>
        <success>)</success>
        <attributes>[[s, t, r, i, n, g]]</attributes>
      </value_>
      <success>)</success>
      <attributes>[[s, t, r, i, n, g]]</attributes>
    </expr_>
    <success></success>
    <attributes>[[g, n, i, r, t, s]]</attributes>
  </function_call_>
  <success></success>
  <attributes>[[g, n, i, r, t, s]]</attributes>
</expr_>
input:  ReverseString('string')
eval:   gnirts

<expr_>
  <try>Concatenate('string'</try>
  <function_call_>
    <try>Concatenate('string'</try>
    <expr_>
      <try>'string', 987)</try>
      <function_call_>
        <try>'string', 987)</try>
        <fail/>
      </function_call_>
      <value_>
        <try>'string', 987)</try>
        <string_>
          <try>'string', 987)</try>
          <success>, 987)</success>
          <attributes>[[s, t, r, i, n, g]]</attributes>
        </string_>
        <success>, 987)</success>
        <attributes>[[s, t, r, i, n, g]]</attributes>
      </value_>
      <success>, 987)</success>
      <attributes>[[s, t, r, i, n, g]]</attributes>
    </expr_>
    <expr_>
      <try> 987)</try>
      <function_call_>
        <try> 987)</try>
        <fail/>
      </function_call_>
      <value_>
        <try> 987)</try>
        <success>)</success>
        <attributes>[987]</attributes>
      </value_>
      <success>)</success>
      <attributes>[987]</attributes>
    </expr_>
    <success></success>
    <attributes>[[s, t, r, i, n, g, 9, 8, 7]]</attributes>
  </function_call_>
  <success></success>
  <attributes>[[s, t, r, i, n, g, 9, 8, 7]]</attributes>
</expr_>
input:  Concatenate('string', 987)
eval:   string987

<expr_>
  <try>Concatenate('The Ans</try>
  <function_call_>
    <try>Concatenate('The Ans</try>
    <expr_>
      <try>'The Answer Is ', An</try>
      <function_call_>
        <try>'The Answer Is ', An</try>
        <fail/>
      </function_call_>
      <value_>
        <try>'The Answer Is ', An</try>
        <string_>
          <try>'The Answer Is ', An</try>
          <success>, AnswerToLTUAE())</success>
          <attributes>[[T, h, e,  , A, n, s, w, e, r,  , I, s,  ]]</attributes>
        </string_>
        <success>, AnswerToLTUAE())</success>
        <attributes>[[T, h, e,  , A, n, s, w, e, r,  , I, s,  ]]</attributes>
      </value_>
      <success>, AnswerToLTUAE())</success>
      <attributes>[[T, h, e,  , A, n, s, w, e, r,  , I, s,  ]]</attributes>
    </expr_>
    <expr_>
      <try> AnswerToLTUAE())</try>
      <function_call_>
        <try> AnswerToLTUAE())</try>
        <success>)</success>
        <attributes>[42]</attributes>
      </function_call_>
      <success>)</success>
      <attributes>[42]</attributes>
    </expr_>
    <success></success>
    <attributes>[[T, h, e,  , A, n, s, w, e, r,  , I, s,  , 4, 2]]</attributes>
  </function_call_>
  <success></success>
  <attributes>[[T, h, e,  , A, n, s, w, e, r,  , I, s,  , 4, 2]]</attributes>
</expr_>
input:  Concatenate('The Answer Is ', AnswerToLTUAE())
eval:   The Answer Is 42