glog Notes for Windows users

Google glog defines a severity level ERROR, which is also defined in windows.h . You can make glog not define INFOWARNINGERROR, and FATAL by definingGLOG_NO_ABBREVIATED_SEVERITIES before including glog/logging.h . Even with this macro, you can still use the iostream like logging facilities:

  #define GLOG_NO_ABBREVIATED_SEVERITIES
  #include <windows.h>
  #include <glog/logging.h>

  // ...

  LOG(ERROR) << "This should work";
  LOG_IF(ERROR, x > y) << "This should be also OK";

However, you cannot use INFOWARNINGERROR, and FATAL anymore for functions defined in glog/logging.h .

  #define GLOG_NO_ABBREVIATED_SEVERITIES
  #include <windows.h>
  #include <glog/logging.h>

  // ...

  // This won't work.
  // google::FlushLogFiles(google::ERROR);

  // Use this instead.
  google::FlushLogFiles(google::GLOG_ERROR);

If you don't need ERROR defined by windows.h, there are a couple of more workarounds which sometimes don't work:

  • #define WIN32_LEAN_AND_MEAN or NOGDI before you #include windows.h .
  • #undef ERROR after you #include windows.h .
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章