本文共 1016 字,大约阅读时间需要 3 分钟。
Glog是google推出的一个log库,可以运行在linux和windows下。对于需要跨平台运行的C++程序使用glog作为log库是一个不错的选择。这里简单介绍下glog在linux和windows下编译和使用
1 linux编译
Download
Unzip glog-master.zip
Then cd glog-master directory
./autogen.sh && ./configure && make && sudo make install
The lib will be installed at /usr/local/lib/libglog.so
/usr/local/include/glog
注意:2020.9月之后,glog不再支持autogen的方式编译了,请使用cmake编译,编译方法见:
2 windows 编译
在glog目录下创建cmake_build目录,
启动powershell进入cmake_build目录,运行:
cmake -G "Visual Studio 15 2017" -DBUILD_SHARED_LIBS=yes -DBUILD_TESTING=no -T host=x64 -A x64 ..
命令结束后,会在cmake_build目录下产生glog.sln工程文件
使用Visual Studio 2017打开glog.sln工程文件,编译如下所示:
编译完成后,库文件位于cmake_build\Release目录:
3 usage
The manual document is at glog-master/doc.
Run “firefox ./glog.html” will open the document.
一个简单的例子如下:
#include <glog/logging.h>
FLAGS_log_dir = "./../../delivery/bin";
FLAGS_stderrthreshold = 0;
google::InitGoogleLogging(“name”);
// keep your logs for 7 days
google::EnableLogCleaner(7);
LOG(INFO) << "Constructor starting, configure file is " << argv[1];
转载地址:https://blog.csdn.net/lclfans1983/article/details/108203271 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!