Windows 10上源码编译glog和gflags 编写glog-config.cmake和gflags-config.cmake | compile glog and glags on windows from source
本文首发于个人博客https://kezunlin.me/post/bb64e398/,欢迎阅读!
compile glog v0.3.5 and glags on windows from source.
Series
Guide
version
- glog: v0.3.5 https://github.com/google/glog/archive/v0.3.5.zip
- gflag: v2.2.1 https://github.com/schuhschuh/gflags/archive/v2.2.1.zip
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
includeandlib/gflags.lib, andbin/gflags.dll
modify
CMAKE/CMAKE_INSTALL_PREFIXto a non-system folder, otherwise you will need administrative privileges to run INSTALL project.
glog
Notice:
we have to new entry withBUILD_SHARED_LIBwith valueON, because by default,glogisstatic librarywith 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
includeandlib/glog.lib, andbin/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.dllandglog.dllto 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
- configure-google-glog-and-gflags-for-c
- building-google-glog-with-cmake-on-linux
- glog install
- Installing-Glog-on-Ubuntu-14.04
- installing-glog-on-windows
- glog usage
- glog error
History
- 20180206: created.
- 20180207: add multiple processor and build dependency part for windows.
- 20180209: add error and solutions
Copyright
- Post author: kezunlin
- Post link: https://kezunlin.me/post/bb64e398/
- Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.
Windows 10上源码编译glog和gflags 编写glog-config.cmake和gflags-config.cmake | compile glog and glags on windows from source的更多相关文章
- 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 ...
- [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 ...
- windows 10上源码编译dlib教程 | compile dlib on windows 10
本文首发于个人博客https://kezunlin.me/post/654a6d04/,欢迎阅读! compile dlib on windows 10 Series Part 1: compile ...
- 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 ...
- windows 10 上源码编译opengv | compile opengv on windows 10 from source
本文首发于个人博客https://kezunlin.me/post/51cd9fa0/,欢迎阅读! compile opengv on windows 10 from source Series co ...
- 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 ...
- [Windows篇] 在windows 10上源码编译gtest 并编写CMakeLists.txt
本文首发于个人博客https://kezunlin.me/post/aca50ff8/,欢迎阅读! compile gtest on windows 10 Guide compile gtest on ...
- 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 ...
- CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境
CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境 什么是LNMP? LNMP(别名LEMP)是指由Linux, Nginx, MySQL/MariaDB, PHP/ ...
随机推荐
- Uipath 勾选checkbox
东京IT青年前线 http://www.rpatokyo.com/ Uipath 勾选checkbox 使用check Activity可以对check box 复选框进行勾选. 虽然Click也可以 ...
- vue-cli3 搭建 vue 项目
vue-cli3 搭建 vue 项目 项目是在mac的环境下配置的 win的同学请移步[https://www.cnblogs.com/zhaomeizi/p/8483597.html] 安装 nod ...
- Android SDK安装与环境变量的配置(windows系统)
(一)下载Android SDK压缩包 解压后即可(全英文路径,以免后续出现乱码) (1)下载地址:http://tools.android-studio.org/index.php/sdk
- 疯狂Java:突破程序员基本功的16课-李刚编著 学习笔记(未完待续)
突破程序员基本功(16课) 数组 静态语言: 在编译的时候就能确定数据类型的语言,大多静态语言要求在使用变量之前必须声明数据类型(少数具有强推导能力的现代语言不用) 动态语言: 在程序运行时确定数据类 ...
- OptimalSolution(2)--二叉树问题(2)BST、BBT、BSBT
一.判断二叉树是否为平衡二叉树(时间复杂度O(N)) 平衡二叉树就是:要么是一棵空树,要么任何一个节点的左右子树高度差的绝对值不超过1. 解法:整个过程为二叉树的后序遍历.对任何一个节点node来说, ...
- 消息队列 ActiveMQ 、RocketMQ 、RabbitMQ 和 Kafka 如何选择?
「 预计阅读 6 分钟 」 旁白:这是一篇拖更了N久的文章...0.0(看不见我~) 往期回顾 前端框架 jQuery 和 Vue 如何选择? 安全框架 Shiro 和 Spring Security ...
- Java对象的"后事处理"——垃圾回收(二)
1 先谈Finalize() finalize()能做的所有工作,使用try-finally或者其他方式都可以做得更好.更及时,所以笔者建议大家完全可以忘掉Java语言中有这个方法的存在. ——< ...
- 使用position设置经典的网站前端结构
能脱离文档流的设置: float:left/right position:absolute; 绝对定位 position:fixed; 固定定位 //搞清楚position的属性值的意思就容易明白 使 ...
- javaScipt类定义和实现
最近在几个群上经常看到有人问在一个类里的一个 function 怎么调用 this. 定义后公开的方法.现发一篇类实现的随笔.首先说说类,在一个类里我们会有以下的几个特征:1. 公有方法2. 私有 ...
- NOIP 模拟17
最近状态有些不对劲,总是出现各种各样的小错误...... 这次可以说是很水的一套题(T3神仙题除外),T1就是一个优化的暴力,考场上打了一个n的四次方的程序,在距考试结束还有5分钟的时候猜想出来正解, ...