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

glog使用:

项目地址:
git@github.com: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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值