加入收藏 | 设为首页 | 会员中心 | 我要投稿 我爱故事小小网_铜陵站长网 (http://www.0562zz.com/)- 视频终端、云渲染、应用安全、数据安全、安全管理!
当前位置: 首页 > 教程 > 正文

C++开源日志库--Glog的实施

发布时间:2021-11-21 15:41:14 所属栏目:教程 来源:互联网
导读:第一步,下载glog-0.3.3.tar.gz,解压,直接打开google-glog.sln工程文件,如果vs版本不对,让其自动转换 第二步,编译,在Debug下生成libglog.dll、 libglog.lib、libglog_static.lib 第三步,将头文件和lib库拷贝到自己的工程下,由于我暂时是window下使用


第一步,下载glog-0.3.3.tar.gz,解压,直接打开google-glog.sln工程文件,如果vs版本不对,让其自动转换
 
第二步,编译,在Debug下生成libglog.dll、 libglog.lib、libglog_static.lib
 
第三步,将头文件和lib库拷贝到自己的工程下,由于我暂时是window下使用,头文件使用 glog-0.3.3srcwindowsglog
 
第四步,引用到自己工程下,编译发现报错:
 
1>d:workspacevideovideomanagedevicemgrlibgloggloglog_severity.h(55): fatal error C1189: #error :  ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
1>  SessionMgr.cpp
1>d:workspacevideovideomanagedevicemgrlibgloggloglog_severity.h(55): fatal error C1189: #error :  ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
1>  SessionFactory.cpp
1>d:workspacevideovideomanagedevicemgrlibgloggloglog_severity.h(55): fatal error C1189: #error :  ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
1>  RealTimeStreamSession.cpp
1>d:workspacevideovideomanagedevicemgrlibgloggloglog_severity.h(55): fatal error C1189: #error :  ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
1>  main.cpp
1>d:workspacevideovideomanagedevicemgrlibgloggloglog_severity.h(55): fatal error C1189: #error :  ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
1>  GNumGenerator.cpp
1>d:workspacevideovideomanagedevicemgrlibgloggloglog_severity.h(55): fatal error C1189: #error :  ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
1>  DevicControlSession.cpp
1>d:workspacevideovideomanagedevicemgrlibgloggloglog_severity.h(55): fatal error C1189: #error :  ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
1>  CatalogSesssion.cpp
1>d:workspacevideovideomanagedevicemgrlibgloggloglog_severity.h(55): fatal error C1189: #error :  ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
进入log_severity.h头文件查看,是一个宏定义的地方出现了冲突:
 
 
#ifndef GLOG_NO_ABBREVIATED_SEVERITIES
# ifdef ERROR
#  error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
# endif
const int INFO = GLOG_INFO, WARNING = GLOG_WARNING,
  ERROR = GLOG_ERROR, FATAL = GLOG_FATAL;
#endif
解决方法:
 
在工程加上预编译宏GLOG_NO_ABBREVIATED_SEVERITIES
 
C/C++  -->  预处理器  -->  预处理器定义  -->  加上GLOG_NO_ABBREVIATED_SEVERITIES宏  保存,编译通过~
 
第五步,自己的项目中使用
 
#include "glog/logging.h"
int _tmain(int argc, _TCHAR* argv[])
{
 google::InitGoogleLogging((const char *)argv[0]);  //参数为自己的可执行文件名
 
 google::SetLogDestination(google::GLOG_INFO,"./myInfo");
 
 LOG(INFO) << "This is a <Warn> log message..." << ;
 
 
        .....................
 
}
 
 

(编辑:我爱故事小小网_铜陵站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读