<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px; border: 0px; font-size: 13px; font-family: 'Microsoft YaHei', 微软雅黑, Arial, 'Lucida Grande', Tahoma, sans-serif; line-height: 24.0499992370605px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"> 先下载glog最新版,解压里面有*sln文件,如果你安装了VS2005以上版本都可以直接打开,编译即可得到libglog.dll和libglog.lib文件,拷贝文件到你的测试文件夹下,并拷贝src\windows\下的glog目录到你的工程文件下。</p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px; border: 0px; font-size: 13px; font-family: 'Microsoft YaHei', 微软雅黑, Arial, 'Lucida Grande', Tahoma, sans-serif; line-height: 24.0499992370605px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"> 如下是一个测试<span class="wp_keywordlink" style="margin: 0px; padding: 0px; border: 0px; background: transparent;"><a target=_blank href="http://www.xuebuyuan.com/" title="代码" target="_blank" style="text-decoration: none; color: rgb(1, 150, 227);">代码</a></span>,</p>特别注意, 编译生成的 64位库, 使用的时候,只能使用x64, win32 会提示链接错误,一般就是找不到相应的库。
// zm_glog_test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "glog/logging.h"
#include <iostream>
#include <vector>
using namespace std;
#pragma comment(lib,"libglog.lib")
int _tmain(int argc, char* argv[])
{
// Initialize Google's logging library.
google::InitGoogleLogging(argv[0]);
google::SetLogDestination(google::INFO,"E://");
// 设置日志路径 INFO WARNING ERROR FATAL
// ...
char str[20] = "hello log!";
LOG(INFO) << "Found " << google::COUNTER <<endl;
LOG(INFO) << str ;//<< " cookies";
LOG(WARNING) << "warning test"; // 会输出一个Warning日志
LOG(ERROR) << "error test";//会输出一个Error日志
system("pause");
return 0;
}
参考