安装glog和gflags

1.下载

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

2.配置

sudo apt-get install autoconf automake libtool

3.编译&安装

进入源码根目录
./autogen.sh
./configure
make -j 24
sudo make install

4.结果

make[1]: Entering directory '/home/xxx/Downloads/glog'
 /bin/mkdir -p '/usr/local/lib'
 /bin/bash ./libtool   --mode=install /usr/bin/install -c   libglog.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libglog.so.0.0.0 /usr/local/lib/libglog.so.0.0.0
libtool: install: (cd /usr/local/lib && { ln -s -f libglog.so.0.0.0 libglog.so.0 || { rm -f libglog.so.0 && ln -s libglog.so.0.0.0 libglog.so.0; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libglog.so.0.0.0 libglog.so || { rm -f libglog.so && ln -s libglog.so.0.0.0 libglog.so; }; })
libtool: install: /usr/bin/install -c .libs/libglog.lai /usr/local/lib/libglog.la
libtool: install: /usr/bin/install -c .libs/libglog.a /usr/local/lib/libglog.a
libtool: install: chmod 644 /usr/local/lib/libglog.a
libtool: install: ranlib /usr/local/lib/libglog.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the 'LD_RUN_PATH' environment variable
     during linking
   - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
 /bin/mkdir -p '/usr/local/share/doc/glog-0.3.5'
 /usr/bin/install -c -m 644 AUTHORS COPYING ChangeLog INSTALL NEWS README README.windows doc/designstyle.css doc/glog.html '/usr/local/share/doc/glog-0.3.5'
 /bin/mkdir -p '/usr/local/include/glog'
 /usr/bin/install -c -m 644 src/glog/log_severity.h '/usr/local/include/glog'
 /bin/mkdir -p '/usr/local/include/glog'
 /usr/bin/install -c -m 644 src/glog/logging.h src/glog/raw_logging.h src/glog/vlog_is_on.h src/glog/stl_logging.h '/usr/local/include/glog'
 /bin/mkdir -p '/usr/local/lib/pkgconfig'
 /usr/bin/install -c -m 644 libglog.pc '/usr/local/lib/pkgconfig'
make[1]: Leaving directory '/home/xxx/Downloads/glog'

5.下载gflags

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

6.编译&安装

进入源码目录
cmake .
make -j 24
sudo make install

7.简单示例

#include <glog/logging.h>  
//#include<gflags/flags.h>  
int main(int argc,char* argv[]) {  
    // 要使用下面的api,需要安装额外的gflags,以及添加上面注释的头文件   
    // google::ParseCommandLineFlags(&argc, &argv, true);  
  
    // Initialize Google's logging library.  
    google::InitGoogleLogging(argv[0]);  
  
    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目录要事先创建好再在程序中指定才行,亲测。

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏C/C++基础

CMake简介及使用实例

CMake是一个跨平台的建构系统的工具,可以用简单的语句来描述所有平台的安装(编译过程)。他能够输出各种各样的构建文档makefile或者project文件,描...

982
来自专栏用户2442861的专栏

cmake教程5-macro宏定义以及传递参数给源文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/haluoluo211/article/d...

1113
来自专栏FreeBuf

使用CMSTP绕过AppLocker的方法介绍

CMSTP是一个与Microsoft连接管理器配置文件安装程序关联的二进制文件。它接受INF文件,这些文件可以通过恶意命令武器化,以脚本(SCT)和DLL的形式...

683
来自专栏Dawnzhang的开发者手册

spring cloud(学习笔记)微服务启动错误(1)

Error starting ApplicationContext. To display the auto-configuration report re-r...

712
来自专栏挖掘大数据

Standalone模式安装Spark

前言:本篇文章是学习spark的开篇,搭建一个spark的完全分布式集群,与大家共勉。

1860
来自专栏乐沙弥的世界

rman 还原归档日志(restore archivelog)

     听说过还原(restore)数据库,表空间及数据库文件,使用归档日志恢复(recover)数据库,表空间,数据库文件。咦,还有还原归档日志这一说法呢?...

1044
来自专栏LEo的网络日志

windows安装redis

2977
来自专栏散尽浮华

Centos7下使用Ceph-deploy快速部署Ceph分布式存储-操作记录

之前已详细介绍了Ceph分布式存储基础知识,下面简单记录下Centos7使用Ceph-deploy快速部署Ceph环境: 1)基本环境

1023
来自专栏杂烩

canal安装配置 转

a. canal的原理是基于mysql binlog技术,所以这里一定需要开启mysql的binlog写入功能,建议配置binlog模式为row.

672
来自专栏乐沙弥的世界

SELinux: Could not downgrade policy file

在配置nfs服务器,设定selinux时,碰到了SELinux: Could not downgrade policy file的错误提示,下文是其解决方案。

1183

扫码关注云+社区