我正在尝试在 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/