C++ – Cannot open include file – ‘gtest.h’ – No such file or directory

cgoogletestvisual studio 2010

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.

error C1083: Cannot open include file: 'gtest/gtest.h': No such file or directory 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:\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.

Best Answer

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 looked for 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:

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")