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/ ...
随机推荐
- Django之CBV视图源码分析(工作原理)
1.首先我们先在urls.py定义CBV的路由匹配. FBV的路由匹配: 2.然后,在views.py创建一名为MyReg的类: 注意:该类必须继续View类,且方法名必须与请求方式相同(后面会详解) ...
- Apache常见配置
一.yum安装与配置 1.1安装: [root@apache ~]# yum install http\* -y [root@apache ~]# echo "test01" ...
- js更高文档的样式
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- django & celery - 关于并发处理能力和内存使用的小结
背景 众所周知,celery 是python世界里处理分布式任务的好助手,它的出现结合赋予了我们强大的处理异步请求,分布式任务,周期任务等复杂场景的能力. 然鹅,今天我们所要讨论的则是如何更好的在使用 ...
- wfi破解
破解wifi步骤 1.准备字典(常见字典 数字组合.常用姓氏.汉字姓名+年份组合等等) 2.无线网卡 3.查看附近WiFi信息 前言 : 随着无线网络走进我们的生活,在方便了我们的同时又产生了许多的安 ...
- AD中如何插入logo(图片)
图片转成protel altium AD PCB封装 LOGO方法 1. 2. 3. 4.打开下列顺序文件夹 Examples-->Scripts-->Delphiscript Scrip ...
- JavaSE语法
二.JavaSE语法(上) 1.Java 有没有 goto 语句? goto 是 Java 中的保留字,在目前版本的 Java 中没有使用.根据 James Gosling(Java 之父)编写的&l ...
- 机器学习之scikit-learn库
前面讲到了,这个库适合学习,轻量级,所以先学它. 安装就不讲了,简单.不过得先安装numpy和pandas库才能安装scikit-learn库. 如果安装了anaconda得话,会自带有这个库. -- ...
- js基础总结03 --操作数组
修改于 2019-11-10 1 length:长度 <script> var arr = [1,2,3,4,5,6,7,8]; console.log(arr.length);//arr ...
- NOIP模拟赛18 皇帝的烦恼O(∩_∩)O 二分+DP
题目描述 经过多年的杀戮,秦皇终于统一了中国.为了抵御外来的侵略,他准备在国土边境安置n名将军.不幸的是这n名将军羽翼渐丰,开始展露他们的狼子野心了.他们拒绝述职.拒绝接受皇帝的圣旨. 秦皇已经准备好 ...