Cannot open include file with Visual Studio

后端 未结 8 1912
遥遥无期
遥遥无期 2020-12-30 22:26

I have recently gone from Code::Blocks to Visual Studio, and in Code::Blocks one could just add a class and then include it straight away. However, whenever I do the same in

相关标签:
8条回答
  • 2020-12-30 22:49

    For me, it helped to link the projects current directory as such:

    In the properties -> C++ -> General window, instead of linking the path to the file in "additional include directories". Put "." and uncheck "inheret from parent or project defaults".

    Hope this helps.

    0 讨论(0)
  • 2020-12-30 22:51

    If you've tried the other answers and your include file still can't be found, here are some additional debugging steps and sanity-checks:

    • Ensure that you are building to a platform that is supported by your code. (If not, consider removing this platform as a target)
    • Verify that the filename/path is correct. Modify your source code to #include the whole absolute path of the header file instead, and see if the file can be found now. If not, copy-paste the path from your source code into a command line to validate that the file exists at that full path with no typos. Open the header file to ensure you have read access. (Change the source code back when done.)
    • If you've already added the path to Additional Include Directories, try clicking the drop-down combo box for Additional Include Directories, and select <Edit...>. This will show you evaluated values of paths. (If it does not show the correct evaluated values, variables in your path might not be set. Click Macros>> to see variables.) Copy-paste the evaluated path into windows explorer to validate that the path exists.
    • Create a new empty C++ "Windows Console Application" project. Set just the one Include Directory, and #include just the one file in your main.cpp, and see if that builds.
    0 讨论(0)
  • 2020-12-30 22:57

    By default, Visual Studio searches for headers in the folder where your project is ($ProjectDir) and in the default standard libraries directories. If you need to include something that is not placed in your project directory, you need to add the path to the folder to include:

    Go to your Project properties (Project -> Properties -> Configuration Properties -> C/C++ -> General) and in the field Additional Include Directories add the path to your .h file.

    You can, also, as suggested by Chris Olen, add the path to VC++ Directories field.

    0 讨论(0)
  • 2020-12-30 23:04

    I found this post because I was having the same error in Microsoft Visual C++. (Though it seems it's cause was a little different, than the above posted question.)

    I had placed the file, I was trying to include, in the same directory, but it still could not be found.

    My include looked like this: #include <ftdi.h>

    But When I changed it to this: #include "ftdi.h" then it found it.

    0 讨论(0)
  • 2020-12-30 23:06

    You need to set the path for the preprocessor to search for these include files, if they are not in the project folder.

    You can set the path in VC++ Directories, or in Additional Include Directories. Both are found in project settings.

    0 讨论(0)
  • 2020-12-30 23:11

    If your problem is still there it's certainly because you are trying to compile a different version from your current settings.

    For example if you set your Additional Include Directories in Debug x64, be sure that you are compiling with the same configuration.

    Check this: Build > Configuration Manager... > There is problably something like this in your active solution configuration: Debug x86 (Win32) platform.

    0 讨论(0)
提交回复
热议问题