c++ - 无法打开包含文件 - 'gtest.h' - 没有这样的文件或目录

标签 c++ visual-studio-2010 googletest

我正在尝试在 Visual Studio 中构建 gtest,但在获取为项目正确指定的引用和包含时似乎遇到了一些问题。

错误 C1083:无法打开包含文件:“gtest/gtest.h”:没有这样的文件或目录 c:\gtest-1.6.0\src\gtest-all.cc

1>InitializeBuildStatus:
1>  Touching "Debug\GTestBuild.unsuccessfulbuild".
1>ClCompile:
1>  gtest-all.cc
1>c:\gtest-1.6.0\src\gtest-all.cc(40): fatal error C1083: Cannot open include file: 'gtest/gtest.h': No such file or directory
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.61

对于项目,我在项目项目页面> C/C++>附加包含目录列表中添加了对以下内容的引用:

c:\gtest-1.6.0
c:\gtest-1.6.0\src
c:\gtest-1.6.0\include
c:\gtest-1.6.0\include\gtest

but I seem to be missing some other includes or probably did not set this right and would appreciate some help in solving this, and learning how to do this for future as well.

PS. Switching from

#include "gtest/gtest.h"
// The following lines pull in the real gtest *.cc files.
#include "src/gtest.cc"
#include "src/gtest-death-test.cc"
#include "src/gtest-filepath.cc"
#include "src/gtest-port.cc"
#include "src/gtest-printers.cc"
#include "src/gtest-test-part.cc"
#include "src/gtest-typed-test.cc"

#include <gtest/gtest.h>

// The following lines pull in the real gtest *.cc files.
#include <src/gtest.cc>
#include <src/gtest-death-test.cc>
#include <src/gtest-filepath.cc>
#include <src/gtest-port.cc>
#include <src/gtest-printers.cc>
#include <src/gtest-test-part.cc>
#include <src/gtest-typed-test.cc>

不是解决方案。我已经试过了,但没有用。

最佳答案

检查完整的编译输出以查看这些包含目录是否被合并到编译中。它应该看起来像:

...
-Ic:\gtest-1.6.0 -Ic:\gtest-1.6.0\src -Ic:\gtest-1.6.0\include -Ic:\gtest-1.6.0\include\gtest
...

您是否也查找过这些目录中的文件?不要忘记,当您将它包含在目录中时,您必须在以下目录中查找 gtest.h:

c:\gtest-1.6.0\gtest
c:\gtest-1.6.0\src\gtest
c:\gtest-1.6.0\include\gtest
c:\gtest-1.6.0\include\gtest\gtest

(在使用 #include "gtest/gtest.h" 时注意 gtest 子目录)

关于c++ - 无法打开包含文件 - 'gtest.h' - 没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10945386/

相关文章:

c++ - 为什么标准的 C++ 容器适配器不提供明确的功能?

c++ - 阶乘(代码厨师)

c++ - 使用 define 指令获取命名空间名称

c++ - 单元测试变量的真假

c++ - 如何在传递给模拟方法的对象上调用方法

c++ - c_str() ing 字符串 - 除了第一行之外的所有其他行都将丢失

c# - 获取和设置如何影响变量的分配?

c# - 带有 Framework 2.0 的 Visual Studio 2010 命令行

c# - 在执行重建之前不会发生更改

xml - 谷歌测试 : Can I query the name of the test fixture?