C++ 无法打开包含文件 - 'gtest.h' - 没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10945386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot open include file - 'gtest.h' - No such file or directory
提问by Kobojunkie
I am trying to build gtest in Visual Studio, but seem to be having some problems getting the references and includes specified correctly for the project.
我正在尝试在 Visual Studio 中构建 gtest,但似乎在获取引用和为项目正确指定的包含时遇到了一些问题。
error C1083: Cannot open include file: 'gtest/gtest.h': No such file or directory c:\gtest-1.6.0\src\gtest-all.cc
错误 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
To the Project, I added in the Project Project Pages > C/C++>Additional Include Directories list references to the following:
对于项目,我在项目项目页面> 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"
To
到
#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>
is not a solution. I have tried this and it does not work.
不是解决方案。我试过这个,但它不起作用。
采纳答案by Component 10
Check the full compilation output to see whether these include directories are being incorporated into the compilation. It should look something like:
检查完整的编译输出以查看这些包含目录是否被合并到编译中。它应该看起来像:
...
-Ic:\gtest-1.6.0 -Ic:\gtest-1.6.0\src -Ic:\gtest-1.6.0\include -Ic:\gtest-1.6.0\include\gtest
...
Have you also lookedfor the file in these directories? Don't forget that as you're including it with a directory, you'll have to look for gtest.h
in the following directories:
您是否也在这些目录中查找过文件?不要忘记,当您将它包含在目录中时,您必须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
(Note the gtest
subdirectory as you using #include "gtest/gtest.h"
)
(注意使用时的gtest
子目录#include "gtest/gtest.h"
)
回答by Fraser
If you look in the Property Pages for the file gtest-all.cc, its Additional Include Directories field should show:
如果您在属性页中查找文件 gtest-all.cc,其附加包含目录字段应显示:
..;..\include;%(AdditionalIncludeDirectories)
if you used the provided msvc\gtest.sln, or else:
如果您使用了提供的 msvc\gtest.sln,或者:
C:/gtest-1.6.0/include;C:/gtest-1.6.0;%(AdditionalIncludeDirectories)
if you used CMake to create a VS solution.
如果您使用 CMake 创建 VS 解决方案。
If the field is empty, then it is not getting the directories you set for the full project, since they are applied via the %(AdditionalIncludeDirectories)
variable. If this isthe case, it may be worth getting a fresh download and starting again, since the build is no longer in good shape.
如果该字段为空,则它不会获取您为整个项目设置的目录,因为它们是通过%(AdditionalIncludeDirectories)
变量应用的。如果是这种情况,可能值得重新下载并重新开始,因为构建不再处于良好状态。