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

compile glog v0.3.5 and glags on windows from source.

Series

Guide

version

gflags

do not use offical version,instead use https://github.com/schuhschuh/gflags.git

git clone https://github.com/schuhschuh/gflags.git
cd gflags
mkdir windows-build
cd windows-build
cmake-gui ..

with options

BUILD_SHARED_LIBS ON
INSTALL_SHARED_LIBS ON
INSTALL_STATIC_LIBS OFF
CMAKE_CONFIGURATION_TYPES Release # Release
REGISTER_INSTALL_PREFIX OFF CMAKE_INSTALL_PREFIX D:/gflags
#NAMESPACE google;gflags
NAMESPACE google

or command

	cmake -DGFLAGS_NAMESPACE=google -DCMAKE_CXX_FLAGS=-fPIC ..

we get include and lib/gflags.lib, and bin/gflags.dll

modify CMAKE/CMAKE_INSTALL_PREFIX to a non-system folder, otherwise you will need administrative privileges to run INSTALL project.

glog

Notice:

we have to new entry with BUILD_SHARED_LIB with value ON , because by default, glog is static library with extension .lib.

wget https://github.com/google/glog/archive/v0.3.5.zip

mkdir windows-build
cd windows-build
cmake-gui ..

with options

#WITH_GFLAGS ON
#gflags_DIR D:/gflags/lib/cmake/gflags WITH_GFLAGS OFF
CMAKE_INSTALL_DIR d:/glog
CMAKE_CONFIGURATION_TYPES Release # Release BUILD_SHARED_LIBS ON # new by hand

generate sln and open with Visual Studio 2015 compile and install.

and we get preprocessors from glog

WIN32
_WINDOWS
NDEBUG
GLOG_NO_ABBREVIATED_SEVERITIES
GOOGLE_GLOG_IS_A_DLL=1
GOOGLE_GLOG_DLL_DECL=__declspec(dllexport)
GFLAGS_IS_A_DLL=1
CMAKE_INTDIR="Release"
LIBGLOG_EXPORTS

we get include and lib/glog.lib, and bin/glog.dll

multiple processor compile

  • windows: set_target_properties(main PROPERTIES COMPILE_FLAGS "/MP")
  • linux: make -j8

with cmake options /MD added to CMAKE_CXX_FLAGS_RELEASE

CMAKE_CXX_FLAGS_RELEASE /MD /O2 /Ob2 /DNDEBUG /MP

or

with CMakeLists.txt

if(MSVC) # WIN32
set_target_properties(target1 PROPERTIES COMPILE_FLAGS "/MP")
set_target_properties(target2 PROPERTIES COMPILE_FLAGS "/MP")
set_target_properties(target3 PROPERTIES COMPILE_FLAGS "/MP")
endif()

project dependency

select ALL-BUILD and change build order by hand.

ZERO_CHECK
CarConfig
CarUtil
CarModel
CarDatabase
a_main
a_unit_tests
data_client
data_server
example_jpeg
example_thread
ALL_BUILD

Example Code

CMakeLists.txt

#find_package(glog 0.3.5 REQUIRED)
# no GLOG_INCLUDE_DIRS GLOG_LIBRARIES, we only use `glog::glog` as target find_package(glog REQUIRED) add_executable(main main.cpp)
target_link_libraries (main glog::glog)

glog include directory will be imported automatically.

gflags-config.cmake

set(GFLAGS_FOUND TRUE) # auto
set(GFLAGS_ROOT_DIR "D:/gflags") find_path(GFLAGS_INCLUDE_DIR NAMES gflags/gflags.h PATHS "${GFLAGS_ROOT_DIR}/include")
mark_as_advanced(GFLAGS_INCLUDE_DIR) # show entry in cmake-gui find_library(GFLAGS_LIBRARY NAMES gflags.lib PATHS "${GFLAGS_ROOT_DIR}/lib")
mark_as_advanced(GFLAGS_LIBRARY) # show entry in cmake-gui # use xxx_INCLUDE_DIRS and xxx_LIBRARIES in CMakeLists.txt
set(GFLAGS_INCLUDE_DIRS ${GFLAGS_INCLUDE_DIR} )
set(GFLAGS_LIBRARIES ${GFLAGS_LIBRARY} ) message( "gflags-config.cmake " ${GFLAGS_ROOT_DIR})

glog-config.cmake

set(GLOG_FOUND TRUE) # auto
set(GLOG_ROOT_DIR "D:/glog") find_path(GLOG_INCLUDE_DIR NAMES glog/logging.h PATHS "${GLOG_ROOT_DIR}/include")
mark_as_advanced(GLOG_INCLUDE_DIR) # show entry in cmake-gui find_library(GLOG_LIBRARY NAMES glog.lib PATHS "${GLOG_ROOT_DIR}/lib")
mark_as_advanced(GLOG_LIBRARY) # show entry in cmake-gui # use xxx_INCLUDE_DIRS and xxx_LIBRARIES in CMakeLists.txt
set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR} )
set(GLOG_LIBRARIES ${GLOG_LIBRARY} ) message( "glog-config.cmake " ${GLOG_ROOT_DIR})

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;
}

copy gflags.dll and glog.dll to main executable folder.

errors

error:

fatal error C1189: #error :  ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.

solution:

find_package(GFLAGS REQUIRED) # user-defined
find_package(GLOG REQUIRED) # user-defined
include_directories(${GFLAGS_INCLUDE_DIRS})
include_directories(${GLOG_INCLUDE_DIRS}) # add macro GLOG_NO_ABBREVIATED_SEVERITIES
add_definitions( -DGLOG_NO_ABBREVIATED_SEVERITIES )

Reference

History

  • 20180206: created.
  • 20180207: add multiple processor and build dependency part for windows.
  • 20180209: add error and solutions

Copyright

Windows 10上源码编译glog和gflags 编写glog-config.cmake和gflags-config.cmake | compile glog and glags on windows from source的更多相关文章

  1. windows 10 上源码编译OpenCV并支持CUDA | compile opencv with CUDA support on windows 10

    本文首发于个人博客https://kezunlin.me/post/6580691f/,欢迎阅读! compile opencv with CUDA support on windows 10 Ser ...

  2. [Part 4] 在Windows 10上源码编译PCL 1.8.1支持VTK和QT,可视化三维点云

    本文首发于个人博客https://kezunlin.me/post/2d809f92/,欢迎阅读! Part-4: Compile pcl with vtk qt5 support from sour ...

  3. windows 10上源码编译dlib教程 | compile dlib on windows 10

    本文首发于个人博客https://kezunlin.me/post/654a6d04/,欢迎阅读! compile dlib on windows 10 Series Part 1: compile ...

  4. windows 10 上源码编译boost 1.66.0 | compile boost 1.66.0 from source on windows 10

    本文首发于个人博客https://kezunlin.me/post/854071ac/,欢迎阅读! compile boost 1.66.0 from source on windows 10 Ser ...

  5. windows 10 上源码编译opengv | compile opengv on windows 10 from source

    本文首发于个人博客https://kezunlin.me/post/51cd9fa0/,欢迎阅读! compile opengv on windows 10 from source Series co ...

  6. windows 10上源码编译libjpeg-turbo和使用教程 | compile and use libjpeg-turbo on windows 10

    本文首发于个人博客https://kezunlin.me/post/83828674/,欢迎阅读! compile and use libjpeg-turbo on windows 10 Series ...

  7. [Windows篇] 在windows 10上源码编译gtest 并编写CMakeLists.txt

    本文首发于个人博客https://kezunlin.me/post/aca50ff8/,欢迎阅读! compile gtest on windows 10 Guide compile gtest on ...

  8. Windows 10上源码编译Poco并编写httpserver和tcpserver | compile and install poco cpp library on windows

    本文首发于个人博客https://kezunlin.me/post/9587bb47/,欢迎阅读! compile and install poco cpp library on windows Se ...

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

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

随机推荐

  1. 020 - FreeRTOS学习路线总结

    零.为什么写? 在H7-tools预售群里,有位朋友提出如何学习FreeRTOS这类的问题,便由此总结下自己的学习路线.最近又打算接触RTT,和FreeRTOS做个对比. 文章分两步来讲,学习路线和学 ...

  2. org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping

    配置spring+shiro时,启动tomcat报错异常 严重: Context initialization failedorg.springframework.beans.factory.Bean ...

  3. 轻量级CNN模型之squeezenet

    SqueezeNet 论文地址:https://arxiv.org/abs/1602.07360 和别的轻量级模型一样,模型的设计目标就是在保证精度的情况下尽量减少模型参数.核心是论文提出的一种叫&q ...

  4. 将windows项目移植到linux上

    提要:由于项目使用java开发,移植中没有什么编译问题(移植很快,但小问题多) 1.移植过程中遇到的问题: (1).由于项目中使用了 1024以下的端口号,导致网络通信一直出错 原因:因为Linux要 ...

  5. 认证授权-学习笔记1-OAuth 2.0

    简介 客户端必须得到用户的授权(authorization grant),才能获得令牌(access token).OAuth 2.0定义了四种授权方式. 授权码模式(authorization co ...

  6. JVM概述和类加载器

    JVM概述 1.Java虚拟机所管理的内存包括以下几个运行时数据区域:   ①.程序计数器     程序计数器是一块较小的内存空间,可以看做是当前线程所执行的字节码的行号指示器,字节码解释器工作时就是 ...

  7. unity image 设置图片

    从任意文件目录下读取文件并在unity中显示: 1)读取目标文件 byte[] imageByte = File.ReadAllBytes(imagePath); 2)转换成纹理 texture.Lo ...

  8. DirectX9:基础篇 第一章 初始化Direct3D

    一.简介 二.Direct3D类 1.创建D3D类 IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion); //Direct3D类的创建 IDirec ...

  9. ArangoDB安装方法整理

    目录 方法一:镜像安装 方法二:离线安装 方法三:在线安装 启动与停止服务 一.镜像安装(推荐方法) 安装docker 安装方法参见docker安装方法整理. 安装arangodb镜像: docker ...

  10. [考试反思]1029csp-s模拟测试92:弱智

    我只能这么评价我自己. 看这个提交时间...我没话可说... T1半个世界都A了还是切不掉.又一次挂细节. T2不会证明的乱搞(虽然可以证明)A了没什么可说的算是水过. T3之前水过的题(打的次正解) ...