Cannot open include file - 'gtest.h' - No such file or directory

32,476

Solution 1

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

Solution 2

If you look in the Property Pages for the file gtest-all.cc, its Additional Include Directories field should show:

..;..\include;%(AdditionalIncludeDirectories)

if you used the provided msvc\gtest.sln, or else:

C:/gtest-1.6.0/include;C:/gtest-1.6.0;%(AdditionalIncludeDirectories)

if you used CMake to create a VS solution.

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 is the case, it may be worth getting a fresh download and starting again, since the build is no longer in good shape.

Share:
32,476
Kobojunkie
Author by

Kobojunkie

I am a dedicated Developer at heart coding and pushing my way to becoming a master. Would really appreciate if you those who are not willing to share their knowledge, without question, avoid even posting a responses to questions asked. Some of us are here to learn from those who have know.

Updated on June 09, 2020

Comments

  • Kobojunkie
    Kobojunkie almost 4 years

    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.