You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C++项目引入<glog/logging.h>报错,请求协助解决

引入<glog/logging.h>时编译报错求助

test.cc代码

#include <glog/logging.h>

int main(int argc, char* argv[]) {
    // Initialize Google’s logging library.
    google::InitGoogleLogging(argv[0]);

    // ...
    LOG(INFO) << "Found cookies";
}

CMakeLists.txt配置

cmake_minimum_required (VERSION 3.16)
project (myproj VERSION 1.0)

find_package (glog 0.6.0 REQUIRED)

add_executable (myapp test.cc)
target_link_libraries (myapp glog::glog)

编译错误信息

[build] In file included from /home/user/Documents/projects/hist/hist/src/test.cc:4:
[build] /usr/local/include/glog/logging.h:60:4: error: #error <glog/logging.h> was not included correctly. See the documention for how to consume the library.
[build]    60 | #  error <glog/logging.h> was not included correctly. See the documention for how to consume the library.
[build]       |    ^~~~~
[build] In file included from /usr/local/include/glog/logging.h:63,
[build]                  from /home/user/Documents/projects/hist/hist/src/test.cc:4:
[build] /usr/local/include/glog/flags.h:45:4: error: #error <glog/flags.h> was not included correctly. See the documention for how to consume the library.
[build]    45 | #  error <glog/flags.h> was not included correctly. See the documention for how to consume the library.
[build]       |    ^~~~~
[build] In file included from /usr/local/include/glog/logging.h:77,
[build]                  from /home/user/Documents/projects/hist/hist/src/test.cc:4:
[build] /usr/local/include/glog/log_severity.h:38:4: error: #error <glog/log_severity.h> was not included correctly. See the documention for how to consume the library.
[build]    38 | #  error <glog/log_severity.h> was not included correctly. See the documention for how to consume the library.
[build]       |    ^~~~~
[build] In file included from /usr/local/include/glog/logging.h:78,
[build]                  from /home/user/Documents/projects/hist/hist/src/test.cc:4:
[build] /usr/local/include/glog/vlog_is_on.h:71:4: error: #error <glog/vlog_is_on.h> was not included correctly. See the documention for how to consume the library.
[build]    71 | #  error <glog/vlog_is_on.h> was not included correctly. See the documention for how to consume the library.
[build]       |    ^~~~~
[build] In file included from /usr/local/include/glog/logging.h:63,
[build]                  from /home/user/Documents/projects/hist/hist/src/test.cc:4:
[build] /usr/local/include/glog/flags.h:105:1: error: ‘GLOG_EXPORT’ does not name a type
[build]   105 | DECLARE_int32(logemaillevel);
[build]       | ^~~~~~~~~~~~~
[build] /usr/local/include/glog/flags.h:105:1: error: ‘FLAGS_logemaillevel’ has not been declared in ‘fLI’
[build]   105 | DECLARE_int32(logemaillevel);
[build]       | ^~~~~~~~~~~~~
[build] /usr/local/include/glog/flags.h:106:1: error: ‘GLOG_EXPORT’ does not name a type
[build]   106 | DECLARE_int32(logcleansecs);
[build]       | ^~~~~~~~~~~~~
[build] /usr/local/include/glog/flags.h:106:1: error: ‘FLAGS_logcleansecs’ has not been declared in ‘fLI’
[build]   106 | DECLARE_int32(logcleansecs);
[build]       | ^~~~~~~~~~~~~
...

已按glog官方README完成安装,所有测试均通过,也参考过相关解决方案,但问题仍未解决,恳请协助排查。

内容的提问来源于stack exchange,提问作者Samah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 22:00:07