Glog地址:https://github.com/google/glog
平台:windows
開發工具:VS2010
下載完成之後,用VS2010進行編譯,默認是vs2008讓其自動轉換,如圖所示。
編譯,在Debug下生成libglog.dll、 libglog.lib、libglog_static.lib
將頭文件和lib庫拷貝到自己的工程下,頭文件使用src\windows\glog
這一步很重要
1、配置include和lib,讓vs找到頭文件和庫文件
2、鏈接器輸入lib靜態文件
3、預處理器設置
這個參數不設置會報如下錯誤:
1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_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:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_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:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_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:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_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:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_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:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_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:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_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:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_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.
#include "stdafx.h" #includeint _tmain(int argc, _TCHAR* argv[]) { google::InitGoogleLogging((const char *)argv[0]); //參數為自己的可執行文件名 google::SetLogDestination(google::GLOG_INFO,"./Log"); LOG(INFO) << "Glog test INFO"; LOG(INFO) << "Glog test INFO 2"; return 0; }
這個時候進行生成的時候會報一個錯誤,提示沒有inttypes.h文件。
錯誤1error C1083: 無法打開包括文件:“inttypes.h”: No such file or directoryd:\documents\visual studio 2010\projects\glog\glog\glog\logging.h821glog
這是因為VS2010對C99支持的不好導致的。
解決辦法:
參考文獻:http://www.cnblogs.com/zyl910/archive/2012/08/08/c99int.html
從網上下載一個“inttypes.h”,放到VS2010的VC目錄下的include文件夾中
稍候上傳。。。