Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error

I am trying to build a solution on Visual Studio Community 2017, but I keep getting the error "Cannot open include file: 'stdio.h' ".

I've read through several similar questions, but I still can't fix this problem. It looks like the stdio.h file is called in the stdafx.h file. Below are more details. Any suggestions?

System details:

  • Windows 10
  • Visual Studio Community 2017 v.15.2 (26430.6) -- Installed Desktop Development with C++ (Screenshot: Installation list)

Step 1: I wrote the famous Hello, World! program in C++.

#include "stdafx.h" #include <iostream>  using namespace std;  int main() {     cout << "Hello, World!" << endl;     return 0; } 

Step 2: I clicked on BuildBuild Solution.

Problem: 'stdio.h': No such file or directory. Full Error:

1>------ Build started: Project: HelloWorld, Configuration: Debug Win32 ------ 1>stdafx.cpp 1>c:\users\dahiana mini\desktop\learncpp\helloworld\helloworld\stdafx.h(10):     fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory 1>Done building project "HelloWorld.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

Troubleshooting details and things I've tried:

  1. Configuration Properties* → VC++ Directories Include Directories $(VC_IncludePath);$(WindowsSDK_IncludePath);

  2. Screenshot: Solution Explorer (files in the project)

  3. Code in stdafx.cpp file:

    // stdafx.cpp : source file that includes just the standard includes // HelloWorld.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information  #include "stdafx.h"  // TODO: reference any additional headers you need in STDAFX.H // and not in this file 
  4. Code in stdafx.h file:

    // stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently  #pragma once  #include "targetver.h" #include <stdio.h> #include <tchar.h> 

    NOTE: the #include for <stdio.h> and <tchar.h> both have the red squiggle line underneath, and says "cannot open source file".

    Tried: I tried removing the last two lines, but then I got more errors.

  5. Tried: Since many suggested that stdafx.h is not required, I tried removing just the first line, #include "stdafx.h". But in order for this to work I had to do a little more. See the answer below.

like image 711
dahiana Avatar asked May 27 '17 17:05

dahiana


People also ask

How do you fix Cannot open include file Stdio H?

Do this: Open your turboc2 folder you have tc.exe file inside, beside this file you find another file as named as ' tcinst.exe ' open it. Here you have to change the path of the directory to the path where your INCLUDE folder is located. Same way change the path to library directory also over restart your tc.exe.

Where is Stdio H Visual Studio?

The File Stdio. h is included in the path C:\Program Files (x86)\Windows Kits\10\Include\10.0.

Where is the Stdio h file located in Windows?

The library is in whichever one of the C Runtime Libraries against which you are linking. Those libraries are in the VC\lib folder in the Visual Studio installation directory. Thanks for your answer.


2 Answers

Faced the problem of missing stdlib.h and stdio.h (and maybe more) after installing VS2017 Community on a new computer and migrating a solution from VS2013 to VS2017.

Used @Maxim Akristiniy's proposal, but still got error message regarding toolset compatibility. However VS itself suggested to do solution retarget by right-clicking on the solution in Solution Explorer, then selecting Retarget solution from the menu and the updated Windows SDK Version from the drop-down list.

Now my projects build w/o a problem.

Note that you may need to make the project your startup project for the retargeting to catch.

like image 30
ysap Avatar answered Oct 13 '22 19:10

ysap


I got same problem with a project porting from Visual Studio 2013 to Visual Studio 2017.

Fix: change PropertiesGeneralWindows SDK Version to 10

like image 135
Maxim Akristiniy Avatar answered Oct 13 '22 19:10

Maxim Akristiniy