Linux下安装glog和gflags

安装glog和gflags

1.下载

git clone https://github.com/google/glog

2.配置

sudo apt-get install autoconf automake libtool

3.编译&安装

进入源码根目录(glog文件夹)
./autogen.sh
./configure
make -j 24
sudo make install

4..下载gflags

git clone https://github.com/gflags/gflags

  1. 编译&安装

进入源码目录(即gflags文件夹)
cmake .
make -j 24
sudo make install

6.简单示例

#include   
//#include  
int main(int argc,char* argv[]) {  
    // 要使用下面的api,需要安装额外的gflags,以及添加上面注释的头文件   
    // google::ParseCommandLineFlags(&argc, &argv, true);  

    // Initialize Google's logging library.  
    google::InitGoogleLogging(argv[0]);  

  //需要先在本目录下先建立有个名为“log”的文件夹,否则会报错
    FLAGS_log_dir = "./log";
    //or  google::SetLogDestination(google::GLOG_INFO, "./log_");  

    LOG(INFO) << "hello world";  

    return 0;  
} 

编译时加上glog的动态库

如:g++ test.cc -lglog -lgflags -lpthread -o test

注意,再次提醒,log目录要事先创建好再在程序中指定才行。

然后,运行该程序,可以在log文件夹中找到一个文件,记录“hello world”的相关日志信息。

你可能感兴趣的:(glog)