安装glog和gflags

https://www.cnblogs.com/burningTheStar/p/6986048.html

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
//#include
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目录要事先创建好再在程序中指定才行,亲测。

Happy Ending Every Day

你可能感兴趣的:(安装glog和gflags)