Clion在win10使用Glog & 日志打印到标准输出[glog][打印到标准输出]

glog使用:

项目地址:
[email protected]:xychen5/tryGlog.git
推荐使用类似于clion的ide,然后打开该项目,即可编译运行。

1 主要作用:

能够将glog的日志在cmd中打印
主要调用了函数:

   google::SetStderrLogging(google::INFO); // print the logs whose severity > [info]

2 output:

样例输出代码如下:

I0718 16:09:07.626883 18628 main.cpp:13] glog used in cmd!!

W0718 16:09:07.627887 18628 main.cpp:14] glog used in cmd!!

E0718 16:09:07.628882 18628 main.cpp:15] glog used in cmd!!

F0718 16:09:07.628882 18628 main.cpp:16] glog used in cmd!!

3 使用clion需要注意编译器的版本得和库对应

如果使用x86版本的toolchain,会报错如下:

====================[ Build | tryGlogLion | Debug ]=============================
"Z:\softwares\CLion 2021.1.3\bin\cmake\win\bin\cmake.exe" --build F:\cppTry\tryGlogLion\cmake-build-debug --target tryGlogLion
Scanning dependencies of target tryGlogLion
[ 50%] Building CXX object CMakeFiles/tryGlogLion.dir/main.cpp.obj
main.cpp
[100%] Linking CXX executable tryGlogLion.exe
NMAKE : fatal error U1077: “"Z:\softwares\CLion 2021.1.3\bin\cmake\win\bin\cmake.exe"”: 返回代码“0xffffffff”
Stop.
NMAKE : fatal error U1077: “"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\HostX86\x86\nmake.exe"”: 返回代码“0x2”
Stop.
NMAKE : fatal error U1077: “"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\HostX86\x86\nmake.exe"”: 返回代码“0x2”
Stop.
NMAKE : fatal error U1077: “"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\HostX86\x86\nmake.exe"”: 返回代码“0x2”
Stop.
LINK Pass 1: command "C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1429~1.300\bin\Hostx86\x86\link.exe /nologo @CMakeFiles\tryGlogLion.dir\objects1.rsp /out:tryGlogLion.exe /implib:tryGlogLion.lib /pdb:F:\cppTry\tryGlogLion\cmake-build-debug\tryGlogLion.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:console -LIBPATH:F:\prjs\ThirdParty\glog\lib -LIBPATH:F:\prjs\ThirdParty\gflags\lib glog.lib gflags_static.lib glog.lib gflags_static.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\tryGlogLion.dir/intermediate.manifest CMakeFiles\tryGlogLion.dir/manifest.res" failed (exit code 1120) with the following output:
main.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) void __cdecl google::InitGoogleLogging(char const *)" (__imp_?InitGoogleLogging@google@@YAXPBD@Z),函数 _main 中引用了该符号
main.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall google::LogMessage::LogMessage(char const *,int)" (__imp_??0LogMessage@google@@QAE@PBDH@Z),函数 _main 中引用了该符号
main.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall google::LogMessage::LogMessage(char const *,int,int)" (__imp_??0LogMessage@google@@QAE@PBDHH@Z),函数 _main 中引用了该符号
main.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall google::LogMessage::~LogMessage(void)" (__imp_??1LogMessage@google@@QAE@XZ),函数 _main 中引用了该符号
main.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall google::LogMessage::stream(void)" (__imp_?stream@LogMessage@google@@QAEAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@XZ),函数 _main 中引用了该符号
main.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall google::LogMessageFatal::LogMessageFatal(char const *,int)" (__imp_??0LogMessageFatal@google@@QAE@PBDH@Z),函数 _main 中引用了该符号
main.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall google::LogMessageFatal::~LogMessageFatal(void)" (__imp_??1LogMessageFatal@google@@QAE@XZ),函数 _main 中引用了该符号
main.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) void __cdecl google::SetStderrLogging(int)" (__imp_?SetStderrLogging@google@@YAXH@Z),函数 _main 中引用了该符号
F:\prjs\ThirdParty\glog\lib\glog.lib : warning LNK4272:库计算机类型“x64”与目标计算机类型“x86”冲突
F:\prjs\ThirdParty\gflags\lib\gflags_static.lib : warning LNK4272:库计算机类型“x64”与目标计算机类型“x86”冲突
tryGlogLion.exe : fatal error LNK1120: 8 个无法解析的外部命令

解决方案:
将files->settings->buidl,execut,deploy->toolchains->enviroment->architecture设置为x86_amd64

猜你喜欢

转载自blog.csdn.net/cxy_hust/article/details/118878837