本文首发于个人博客https://kezunlin.me/post/977f5125/,欢迎阅读!

compile glog and glags on ubuntu 16.04

Series

Guide

version

wget https://github.com/schuhschuh/gflags/archive/v2.2.1.tar.gz
wget https://github.com/google/glog/archive/v0.3.5.tar.gz

gflags

cd gflags
mkdir build
cd build
cmake-gui ..

with options

BUILD_SHARED_LIBS ON
INSTALL_SHARED_LIBS ON
INSTALL_STATIC_LIBS OFF
CMAKE_CONFIGURATION_TYPES Release
REGISTER_INSTALL_PREFIX OFF #NAMESPACE google;gflags
NAMESPACE google

compile and install

make -j8
sudo make install

gflags-config.cmake

comes from caffe/cmake/Modules/FindGFlags.cmake

# - Try to find GFLAGS
#
# The following variables are optionally searched for defaults
# GFLAGS_ROOT_DIR: Base directory where all GFLAGS components are found
#
# The following are set after configuration is done:
# GFLAGS_FOUND
# GFLAGS_INCLUDE_DIRS
# GFLAGS_LIBRARIES
# GFLAGS_LIBRARYRARY_DIRS include(FindPackageHandleStandardArgs) set(GFLAGS_ROOT_DIR "" CACHE PATH "Folder contains Gflags") # We are testing only a couple of files in the include directories
if(WIN32)
find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h
PATHS ${GFLAGS_ROOT_DIR}/src/windows)
else()
find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h
PATHS ${GFLAGS_ROOT_DIR})
endif() if(MSVC)
find_library(GFLAGS_LIBRARY_RELEASE
NAMES libgflags
PATHS ${GFLAGS_ROOT_DIR}
PATH_SUFFIXES Release) find_library(GFLAGS_LIBRARY_DEBUG
NAMES libgflags-debug
PATHS ${GFLAGS_ROOT_DIR}
PATH_SUFFIXES Debug) set(GFLAGS_LIBRARY optimized ${GFLAGS_LIBRARY_RELEASE} debug ${GFLAGS_LIBRARY_DEBUG})
else()
find_library(GFLAGS_LIBRARY gflags)
endif() find_package_handle_standard_args(GFlags DEFAULT_MSG GFLAGS_INCLUDE_DIR GFLAGS_LIBRARY) if(GFLAGS_FOUND)
set(GFLAGS_INCLUDE_DIRS ${GFLAGS_INCLUDE_DIR})
set(GFLAGS_LIBRARIES ${GFLAGS_LIBRARY})
message(STATUS "Found gflags (include: ${GFLAGS_INCLUDE_DIR}, library: ${GFLAGS_LIBRARY})")
mark_as_advanced(GFLAGS_LIBRARY_DEBUG GFLAGS_LIBRARY_RELEASE
GFLAGS_LIBRARY GFLAGS_INCLUDE_DIR GFLAGS_ROOT_DIR)
endif()

copy gflags-config.cmake to /usr/local/lib/cmake/gflags/

glog

cd glog
mkdir build
cd build
cmake-gui ..

with options

WITH_GFLAGS ON
CMAKE_CONFIGURATION_TYPES Release BUILD_SHARED_LIBS ON # new by hand

compile and install

make -j8
sudo make install

glog-config.cmake

comes from caffe/cmake/Modules/FindGFlags.cmake

# - Try to find Glog
#
# The following variables are optionally searched for defaults
# GLOG_ROOT_DIR: Base directory where all GLOG components are found
#
# The following are set after configuration is done:
# GLOG_FOUND
# GLOG_INCLUDE_DIRS
# GLOG_LIBRARIES
# GLOG_LIBRARYRARY_DIRS include(FindPackageHandleStandardArgs) set(GLOG_ROOT_DIR "" CACHE PATH "Folder contains Google glog") if(WIN32)
find_path(GLOG_INCLUDE_DIR glog/logging.h
PATHS ${GLOG_ROOT_DIR}/src/windows)
else()
find_path(GLOG_INCLUDE_DIR glog/logging.h
PATHS ${GLOG_ROOT_DIR})
endif() if(MSVC)
find_library(GLOG_LIBRARY_RELEASE libglog_static
PATHS ${GLOG_ROOT_DIR}
PATH_SUFFIXES Release) find_library(GLOG_LIBRARY_DEBUG libglog_static
PATHS ${GLOG_ROOT_DIR}
PATH_SUFFIXES Debug) set(GLOG_LIBRARY optimized ${GLOG_LIBRARY_RELEASE} debug ${GLOG_LIBRARY_DEBUG})
else()
find_library(GLOG_LIBRARY glog
PATHS ${GLOG_ROOT_DIR}
PATH_SUFFIXES lib lib64)
endif() find_package_handle_standard_args(Glog DEFAULT_MSG GLOG_INCLUDE_DIR GLOG_LIBRARY) if(GLOG_FOUND)
set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR})
set(GLOG_LIBRARIES ${GLOG_LIBRARY})
message(STATUS "Found glog (include: ${GLOG_INCLUDE_DIR}, library: ${GLOG_LIBRARY})")
mark_as_advanced(GLOG_ROOT_DIR GLOG_LIBRARY_RELEASE GLOG_LIBRARY_DEBUG
GLOG_LIBRARY GLOG_INCLUDE_DIR)
endif()

copy glog-config.cmake to /usr/local/lib/cmake/glog/

Example Code

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

project(glog_proj)

# Locate GTest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS}) find_package(GFLAGS REQUIRED)
include_directories(${GFLAGS_INCLUDE_DIRS}) find_package(GLOG REQUIRED)
include_directories(${GLOG_INCLUDE_DIRS}) # for windows
#add_definitions( -DGLOG_NO_ABBREVIATED_SEVERITIES ) MESSAGE( [Main] " GFLAGS_FOUND = ${GFLAGS_FOUND}")
MESSAGE( [Main] " GFLAGS_INCLUDE_DIRS = ${GFLAGS_INCLUDE_DIRS}")
MESSAGE( [Main] " GFLAGS_LIBRARIES = ${GFLAGS_LIBRARIES}") MESSAGE( [Main] " GLOG_FOUND = ${GLOG_FOUND}")
MESSAGE( [Main] " GLOG_INCLUDE_DIRS = ${GLOG_INCLUDE_DIRS}")
MESSAGE( [Main] " GLOG_LIBRARIES = ${GLOG_LIBRARIES}") add_executable(demo glog_main.cpp)
target_link_libraries (demo ${GLOG_LIBRARIES} ${GFLAGS_LIBRARIES})

main.cpp

#include <gflags/gflags.h>
#include <glog/logging.h> int main(int argc, char **argv)
{
/*
FLAGS_logtostderr = true;
FLAGS_alsologtostderr = true;
FLAGS_colorlogtostderr = true;
FLAGS_log_prefix = true; FLAGS_logbufsecs = 0; //0 means realtime
FLAGS_max_log_size = 10; // MB
*/
google::InitGoogleLogging(argv[0]); // init google logging
google::SetLogDestination(google::GLOG_FATAL, "../log/log_fatal_");
google::SetLogDestination(google::GLOG_ERROR, "../log/log_error_");
google::SetLogDestination(google::GLOG_WARNING, "../log/log_warning_");
google::SetLogDestination(google::GLOG_INFO, "../log/log_info_"); LOG(INFO) << "Hello GLOG"; return 0;
}

Reference

History

  • 20180223: created.

Copyright

ubuntu 16.04上源码编译glog和gflags 编写glog-config.cmake和gflags-config.cmake | compile glog and glags on ubuntu 16.04的更多相关文章

  1. Ubuntu 16.04上源码编译和安装pytorch教程,并编写C++ Demo CMakeLists.txt | tutorial to compile and use pytorch on ubuntu 16.04

    本文首发于个人博客https://kezunlin.me/post/54e7a3d8/,欢迎阅读最新内容! tutorial to compile and use pytorch on ubuntu ...

  2. ubuntu 16.04上源码编译libjpeg-turbo和使用教程 | compile and use libjpeg-turbo on ubuntu 16.04

    本文首发于个人博客https://kezunlin.me/post/9f626e7a/,欢迎阅读! compile and use libjpeg-turbo on ubuntu 16.04 Seri ...

  3. ubuntu 16.04上源码编译和安装cgal并编写CMakeLists.txt | compile and install cgal on ubuntu 16.04

    本文首发于个人博客https://kezunlin.me/post/39ab7ed9/,欢迎阅读最新内容! compile and install cgal on ubuntu 16.04 Guide ...

  4. ubuntu 16.04上源码编译dlib教程 | compile dlib on ubuntu 16.04

    本文首发于个人博客https://kezunlin.me/post/c6ead512/,欢迎阅读! compile dlib on ubuntu 16.04 Series Part 1: compil ...

  5. ubuntu 16.04上源码编译opengv | compile opengv on ubuntu 16.04

    本文首发于个人博客https://kezunlin.me/post/1e5d14ee/,欢迎阅读! compile opengv on ubuntu 16.04 Series compile open ...

  6. Ubuntu 16.04上源码编译Poco并编写cmake文件 | guide to compile and install poco cpp library on ubuntu 16.04

    本文首发于个人博客https://kezunlin.me/post/281dd8cd/,欢迎阅读! guide to compile and install poco cpp library on u ...

  7. ubuntu 14.04上源码编译安装php7

    wget https://downloads.php.net/~ab/php-7.0.0alpha2.tar.bz2 //用winscp把下载好的文件上传到网站中 tar jxf php-7.0.0a ...

  8. CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境

    CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境 什么是LNMP? LNMP(别名LEMP)是指由Linux, Nginx, MySQL/MariaDB, PHP/ ...

  9. 记一次在mac上源码编译curl,使其支持NSS的过程

    一.背景 在一次学习https原理的过程中,希望客户端指定特定的cipher suites来抓包分析SSL/TLS的握手过程,就想到了使用curl工具,而不是使用浏览器. 接下来使用man curl找 ...

随机推荐

  1. SpringBoot HATEOAS用法简介

    REST风格简介 介绍HATEOAS之前先简单介绍一下REST,REST 是 Representational state transfer 的缩写,翻译过来的意思是表达性状态转换.REST是一种架构 ...

  2. 百万年薪python之路 -- RBAC角色权限设计

    RBAC(Role-Based Access Control,基于角色的访问控制),就是用户通过角色与权限进行关联.简单地说,一个用户拥有若干角色,每一个角色拥有若干权限.这样,就构造成"用 ...

  3. RabbitMQ通过DLX实现消息延迟接收

    1. 创建队列WorkQueue,并把WorkQueue跟exchangeWork绑定:2. 创建队列DLXQueue,并把DLXQueue跟exchangeDLX绑定:a. 设置DLXQueue队列 ...

  4. 小白学 Python(10):基础数据结构(列表)(下)

    人生苦短,我选Python 前文传送门 小白学 Python(1):开篇 小白学 Python(2):基础数据类型(上) 小白学 Python(3):基础数据类型(下) 小白学 Python(4):变 ...

  5. IIS服务器文件跨域问题(几乎可以解决大多数跨域问题)

    Windows server 服务器 1:在管理工具中选择,找到IIS 2:打开IIS管理,找到网站 3:找到HTTP响应头标 4:打开HTTP响应头标 5:添加 添加:Access-Control- ...

  6. django-模板之if语句(九)

  7. R语言:绘制知识图谱

    知识图谱主要是通过将应用数学,图形学,信息可视化技术,信息科学等学科的理论与方法与计量学引文分析.共现分析等方法结合,利用可视化的图谱形象地展示学科的核心结构.发展历史.前沿领域以及整体知识架构达到多 ...

  8. DRF之注册器、响应器、分页器

    一.url注册器 通过DRF的视图组件,数据接口逻辑被我们优化到最剩下一个类,接下来,我们使用DRF的url控制器来帮助我们自动生成url,使用步骤如下: 第一步:导入模块 1 from rest_f ...

  9. 【MySQL】MySQL 8.0.X的安装与卸载命令

    1.请读者自行下载MySQL Server https://dev.mysql.com/downloads/mysql/ 2.解压.zip文件 将mysql-8.0.12-winx64.zip解压到 ...

  10. 2019 年容器生态统计报告发布 | 云原生生态周报 Vol. 26

    作者 | 酒祝.天元.元毅.心水.衷源 业界要闻 1.2019 年容器生态统计报告发布  据报告显示,Kubernetes 占据 77% 的容器编排产品份额,Docker 占据 79% 的容器引擎产品 ...