"Fatal error C1083: Cannot open include file" but I have added directory to project

10,103

Solution 1

I have included the complete path to the header file under Project -> Properties -> C/C++ -> General -> Additional Include Directories.

It should be a directory path where detector.h header is located, not a file path.

Check that you have set this option for the active solution configuration. Sometimes it set for Debug, but not for Release and Release configuration is not able to build in such case.

Solution 2

I scratched my head for ~3 hours for a similar problem today. In my case, there were was a hierarchy of build files used to build the binaries. I had to include the directory for my header file (detector.h in your case) as a dependency in the directory and project level Makefile.

project_directory/
- **libraries.mk**
- test/
- [my_test_project]
  - detector_directory/
    - **build.mk**
    - detector.h
    - detector.cpp
  - other_component_directory/
    - other_component.h
    - other_component.cpp

I had to add the path to build.mk and libraries.mk.

HTH!

Share:
10,103
Engineero
Author by

Engineero

A machine learning scientist working in spaaaaace!

Updated on June 05, 2022

Comments

  • Engineero
    Engineero about 2 years

    I think this is a weird problem. I will try to give as much detail as I can. I am attempting to import a header for a custom class in a Visual Studio 2012 test project using:

    #include "detector.h"
    

    And am getting the error

    fatal error C1083: Cannot open include file: 'detector.h': No such file or directory

    I have included the complete path to the folder in which the header file is located under Project -> Properties -> C/C++ -> General -> Additional Include Directories.

    The header file is pretty long, but basically just contains declarations for a class. The detector.cpp file contains the definitions for the class. The directory structure on my file system looks like:

    project_directory/
      - test/
        - [my_test_project]
      - detector_directory/
        - detector.h
        - detector.cpp
      - other_component_directory/
        - other_component.h
        - other_component.cpp
      ...
    

    I am able to #include other_component.h and write and execute tests for that class. I am actually able to include three other classes and write and execute tests for all three, but four classes (including detector) are giving me this same error.

    The whole project_directory/ is checked out from an SVN repository to which only I have contributed so far. I mention that in case there could be some weirdness happening with links or something created for the repo. I think this problem could have arisen after reverting the repo to a previous update, but am not certain if I only noticed it then instead.

    Thanks for your help!

  • Nikita
    Nikita over 7 years
    @Engineero At the top of Project property page you can see available configurations. Select configuration Debug, Release and platform you need to build and check that options, e.g. Additional Include Directories configured properly. Also check that path length for this directory is less than 256 symbols.
  • Engineero
    Engineero over 7 years
    I added the folder in which detector.h is located, not the path to the file. I have fixed this in my problem statement. It looks like the problem came down to which configuration I was setting options for. Thanks!