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
1 | git clone https://github.com/schuhschuh/gflags.git |
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
1 | cmake -DGFLAGS_NAMESPACE=google -DCMAKE_CXX_FLAGS=-fPIC .. |
we get
include
andlib/gflags.lib
, andbin/gflags.dll
modifyCMAKE/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 withBUILD_SHARED_LIB
with valueON
, because by default,glog
isstatic library
with extension.lib
.
1 | wget https://github.com/google/glog/archive/v0.3.5.zip |
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
andlib/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
1 | if(MSVC) # WIN32 |
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
1 | #find_package(glog 0.3.5 REQUIRED) |
glog include directory will be imported automatically.
gflags-config.cmake
1 | set(GFLAGS_FOUND TRUE) # auto |
glog-config.cmake
1 | set(GLOG_FOUND TRUE) # auto |
main.cpp
1 |
|
copy
gflags.dll
andglog.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:
1 | find_package(GFLAGS REQUIRED) # user-defined |
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
History
- 20180206: created.
- 20180207: add multiple processor and build dependency part for windows.
- 20180209: add error and solutions