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

Kob*_*kie 5 c++ googletest visual-studio-2010

我正在尝试在 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
Run Code Online (Sandbox Code Playgroud)

对于项目,我在项目项目页面> 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

但我似乎遗漏了一些其他的包含,或者可能没有正确设置,并希望在解决这个问题时得到一些帮助,并学习如何为将来做到这一点。

附注。切换自

#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"
Run Code Online (Sandbox Code Playgroud)

#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>
Run Code Online (Sandbox Code Playgroud)

不是解决方案。我试过这个,但它不起作用。

Com*_* 10 2

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

...
-Ic:\gtest-1.6.0 -Ic:\gtest-1.6.0\src -Ic:\gtest-1.6.0\include -Ic:\gtest-1.6.0\include\gtest
...
Run Code Online (Sandbox Code Playgroud)

您是否也在这些目录中查找过该文件?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
Run Code Online (Sandbox Code Playgroud)

(请注意gtest您使用的子目录#include "gtest/gtest.h"