Visual studio is unable to find 'assert.h'
Asked Answered
B

5

5

I downloaded Visual Studio 2017 and pulled my solution repo. However, I'm having some issues because it appears that a lot of the files I had on my previous computer were not downloaded in the installation of VS.

I don't want to re-download if I don't have to. I followed the previous steps I took to download VS 2017 on my old computer. Yet, I get the following error:

cannot open source file "assert.h"

but for multiple files, like: errno.h, float.h, corecrt.h, stddef.h, and stdio.h (among 20+ others).

If I right-click and choose the Open document on the line with the error, I get the message:

File '_______.h' not found in current source file's directory or in build system path

However, if I go to my include paths, I can find files like: cassert.h, cerrno.h, ostream.h, but none of the ones that I'm told are missing.

Mainly, I'm wondering if there is a directory with these files I just need to add to the include directory, or whether I just need to admit defeat and reinstall.

Berkow answered 14/9, 2018 at 5:2 Comment(5)
Was the project initially written in C?Shadowgraph
Your installation is incomplete, reinstall. Note that some VS versions/variants required separate installation of an SDK.Jeana
You downloaded the Visual Studio setup package and not just the files from VS on another computer, right?Gargantuan
I can find files like: * cassert.h Really? In C, it is usually assert.h. In C++, this is wrapped into cassert (without suffix). cassert.h looks like a strange mix of this. Out of curiosity, I did a find . -iname "*assert*" -print in Microsoft Visual Studio 12.0/VC/include and found exactly assert.h and cassert.Purposeful
Yes, something very wrong if you really can see a file called cassert.hFairfield
N
10

Using VS2017 I was able to resolve this same issue by:

  1. Right click on solution
  2. Selecting 'Retarget Solution'
  3. Selecting an SDK from the Windows SDK Version dropdown
  4. Clicking OK button

enter image description here

Naphthol answered 1/5, 2019 at 19:49 Comment(0)
S
4

Your Visual Studio 2017 installation is probably missing the C packages (they are not automatically included with the Desktop development with C++ workload).

To install it, start the Visual Studio Installer, go to Individual components, and check Windows Universal C Runtime:

enter image description here

I think this component is also automatically marked for installation when adding the Linux development with C++ workload.

Shana answered 14/9, 2018 at 10:6 Comment(1)
According to documentation, Universal C Runtime in Windows is needed for Windows 8.1 and older only. So on newer systems it does not hurt to install it, but does not help neither. And since W8.1 reached EOS last year, this anwer is less relevant.Anaphase
K
2

I solved the problem by uninstalling my original installation of Visual Studio (2019 version), then reinstalling and including the workload Desktop Development with C++.

In contrast to the above solutions, I did not need (and it did not help) to add the Windows Universal C Runtime.

Kathrinekathryn answered 5/7, 2021 at 15:57 Comment(1)
So we need Windows Kits installed. ThanksAntimagnetic
A
0

This issue is still relevant to this day. I solved it by following this instructions (from 2016):

Search registry entries in:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots

for KitsRoot10 variable, and point it to x86 folder, so replace Program Files with Program Files (x86), to something like C:\Program Files (x86)\Windows Kits\10\.

Also check in this registry path, that this variable is set the same:

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows Kits\Installed Roots

Assuming you have installed Windows SDK - in my case version 10.0.19041, through VS Community 17.11.3 installer. Also as noted in comments, cassert.h does not exist. Only cassert (without extension).

There are several same answers on similar questions, there and there.
And it is possibly the root cause of this problem.

Shame on you Microsoft.

Anaphase answered 15/9 at 9:26 Comment(0)
C
0

What worked for me was changing the "Windows SDK Version" to the latest installed version, in the project properties.

enter image description here

Chemotaxis answered 1/10 at 0:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.