【问题标题】:Google Test include gtest/gtest.h谷歌测试包括 gtest/gtest.h
【发布时间】:2021-05-08 03:39:32
【问题描述】:

我开始使用 Google Test for C++。不幸的是,我在尝试包含头文件时遇到了麻烦。我的小测试程序 sumTest.cpp 的第一行说

#include "gtest/gtest.h"

而 subTest.cpp 与 gtest 位于同一目录中。 gtest 还包含名为 internal 的目录,其中包含 gtest-internal.h 。当我尝试从终端编译 subTest.cpp 时,它说

g++ sumTest.cpp 在 sumTest.cpp:1 中包含的文件中: ./gtest/gtest.h:62:10:致命错误:找不到“gtest/internal/gtest-internal.h”文件 #include "gtest/internal/gtest-internal.h" ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 产生 1 个错误。

所以它找到了文件 gtest/gtest.h 但没有找到文件 gtest/internal/gtest-internal.h ,这对我来说似乎很奇怪。

感谢您的各种帮助。

【问题讨论】:

  • 感谢您的快速回答!那么我是否必须将该路径添加到我的包含搜索路径列表中?
  • 熟悉 CMake 或至少熟悉 install googletest 并为您的项目配置包含/lib 路径可能是值得的。

标签: c++ unix include googletest fatal-error


【解决方案1】:

The line with your error 是 gtest.h 中的第一个本地包含语句。包含 gtest 的目录不在您的包含搜索路径列表中。

gtest/gtest.h 之所以有效,只是因为它与当前文件相关。

您需要将包含目录gtest 的路径添加到您的包含搜索路径列表中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-30
    • 1970-01-01
    • 2012-08-17
    • 2014-04-04
    • 2011-04-02
    • 1970-01-01
    相关资源
    最近更新 更多