Google-glog Log Library Usage notes

Source: Internet
Author: User

Google Glog is a C + + language application-level logging framework that provides C + +-style streaming operations and a variety of helper macros. Tried a bit, feel good, the trial process out a lot of episodes.

1. The Open Source Project homepage has been migrated from https://code.google.com/p/google-glog/to Https://github.com/google/glog. The current major version is 0.3.4.

2. After you download the code, double-click the Google-glog.sln,visual Studio 2015 prompt in the root directory to migrate first, and then compile it successfully.

3, under the solution has four projects: Libglog (is the dynamic link library project, generates Libglog.dll and Libglog.lib), Libglog_static (is the static library project, generates LIBGLOG_ Static.lib, the runtime does not need Libglog.dll), logging_unittest and logging_unittest_static are the corresponding test engineering.

4, do not need to change the project properties. Whether the platform Toolset is Windows XP (V140_XP) does not seem to affect. Glog does not support Unicode wide character sets, and the project property character set preserves multibyte character sets. The "Libglog" in "C + +"-"code generation", the Dynamic Library project must select "Multithreaded DLL" or "Multithreaded Debug DLL", libglog_static static Library project must choose "Multithreading" or "Multithreaded debugging."

5. Compile the library as needed. Taking the static library as an example, the dynamic library will copy the Libglog.dll to the program directory in one more step. Compile debug and release separately, and rename the debug version to Libglog_static_d.lib. Copy the compiled Lib file to the root directory \src\glog, \src\glog is the header file directory. This version of the static library was not found to have a memory leak problem when it was tried.

6. Copy the \glog directory (including header files and library files) to your project directory. You can also create a new library directory, or you can add the corresponding directory in the additional directory of the project properties, which is controlled in the code file. Add the Glog header file in the Project Explorer, and if you add the Glog directory and add the header file, you will be prompted to make an error in the # include path in the Glog header file, and manually delete the "glog\" in the path to resolve.

7. Include "Glog/logging.h" where needed. It is recommended to add to stdafx.h.

8. A # define GOOGLE_GLOG_DLL_DECL must be added using the static library. Dynamic libraries do not have to be added.

9. Because of the macro error defined in Windows.h, it conflicts with the macro error defined in Glog, so if you want to add # define GLOG_NO_ABBREVIATED_ after # include <windows.h> Severities, and the code to use Google::glog_error to replace the original google::error, the corresponding other also changed to: Glog_info, glog_warning, Glog_fatal.

10. Add library file: #pragma comment (lib, "Glog/libglog_static.lib"). For debug and release versions, use #ifdef control.

1 #defineGoogle_glog_dll_decl2 #defineGlog_no_abbreviated_severities3#include"glog/logging.h"4 5 #ifdef DEBUG6     #pragmaComment (lib, "Glog/libglog_static_d.lib")7 #else8     #pragmaComment (lib, "Glog/libglog_static.lib")9 #endif //DEBUG


11. When you use static libraries for your own projects, you must select multithreaded or multithreaded debugging. Use the dynamic library to select either multithreaded DLLs or multithreaded debug DLLs.

12, not finished continue ...

Google-glog Log Library Usage notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.