记录一下glog的安装编译和使用过程,为了以后方便再次配置。
一、glog
When building glog as a standalone project, on Unix-like systems with GNU Make as build tool, the typical workflow is:
- Get the source code and change to it. e.g., cloning with git:
git clone https://github.com/google/glog.git cd glog
- Run CMake to configure the build tree.
cmake -S . -B build -G "Unix Makefiles"
CMake provides different generators, and by default will pick the most relevant one to your environment. If you need a specific version of Visual Studio, use
cmake . -G <generator-name>
, and seecmake --help
for the available generators. Also see-T <toolset-name>
, which can be used to request the native x64 toolchain with-T host=x64
.
- Afterwards, generated files can be used to compile the project.
cmake --build build
- Test the build software (optional).
cmake --build build --target test
- Install the built files (optional).
cmake --build build --target install
二、gflags
下载 git clone https://github.com/gflags/gflags
编译安装命令和上面glog的一样
三、使用
需要引入头文件
#include <glog/logging.h>
#include <iostream>
#include <glog/logging.h>
int main(int argc, char *argv[])
{
google::InitGoogleLogging(argv[0]);
FLAGS_log_dir = "/logdir/";
LOG(INFO) << "hello world";
google::ShutdownGoogleLogging();
return 0;
}