程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> C++開源日志庫Glog的使用(VS2010)

C++開源日志庫Glog的使用(VS2010)

編輯:關於C++

Glog地址:https://github.com/google/glog

平台:windows

開發工具:VS2010

 

1、下載Glog

下載完成之後,用VS2010進行編譯,默認是vs2008讓其自動轉換,如圖所示。

\

編譯,在Debug下生成libglog.dll、 libglog.lib、libglog_static.lib

\

 

\

 

2、新建win32工程

將頭文件和lib庫拷貝到自己的工程下,頭文件使用src\windows\glog

\

 

3、配置VS2010

這一步很重要

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.

 

4、使用測試

#include "stdafx.h"
#include 

int _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文件夾中

 

5、結果

\

 

6、測試demo

稍候上傳。。。

 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved