Multiple relative parent directories in visual studio project settings - c++

I often find that I have problems getting visual studio to find my headers and I think I might have finally found out why: it seems that visual studio does not understand multiple relative directories in project configurations, e.g:
When that directory certainly does exist.
My question is: can somebody confirm this is the case and, if so, is there a reason why they'd do this? Is it a bug or intentional?

Posting as an answer as I can't really fit this into a comment although its a bit frowned upon...
The easiest way to debug this is to run Process Monitor from here, and add a filter to only show access to your file name. I made an example c++ project which tried to load a non existant header #include "Bobby.h" and then added the following filter to Process Monitor:
Path Contains Bobby.h Include
Then I ran the build and got the following output:
CreateFile C:\Users\MyUserName\Documents\Visual Studio 2012\Projects\ConsoleApplication2\ConsoleApplication2\Bobby.h NAME NOT FOUND
CreateFile C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\Bobby.h NAME NOT FOUND
CreateFile C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include\Bobby.h NAME NOT FOUND
CreateFile C:\Program Files (x86)\Windows Kits\8.0\Include\um\Bobby.h NAME NOT FOUND
CreateFile C:\Program Files (x86)\Windows Kits\8.0\Include\shared\Bobby.h NAME NOT FOUND
CreateFile C:\Program Files (x86)\Windows Kits\8.0\Include\WinRT\Bobby.h NAME NOT FOUND
From this output you can easily see where the compiler searched for the header file - It may be good enough to help you understand why it didn't find it.
HTH

Related

Natvis problem after reinstalling VS2017 on different folder

After reinstalling VS2017 on different folder, when I compile an old project I get an error about a missing natvis file (which now is on a different path).
I searched inside the VC++ project files and my user profile but it is not there.
Where natvis information is stored?
Error LNK1104 cannot open file 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Packages\Debugger\Visualizers\std_json.natvis'
Found it, it is inside .vcxproj file but it does not show in explorers.

vcruntime.h missing from Windows include folder?

I'm a beginner and I'm trying to build an open source project for the first time in Windows, but I keep running into file not found errors when building. What I've found so far is that a header file called corecrt.h is located at C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\. This file would include another header file named vcruntime.h. The problem is that vcruntime.h is nowhere to be found in that folder.
I later found that vcruntime.h is located in a separate folder located at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include. This is strange because I'm not sure why corecrt.h would include a file that is not in its own filepath...
I did the bone-headed thing of just copying over vcruntime.h file to the C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\, but this just shifts the problem down the road because vcruntime.h in turn also includes other header files located at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include, and so on.
I think the issue lies with Windows itself. I think I'm missing something that's suppose to install additional header files like vcruntime.h to C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\
So far I've tried uninstalling/reinstalling Windows SDK, and just reinstall Windows as a whole, but still no dice to make the missing files appear in that folder. Can someone give me some insight on this? I've asked this question on Reddit but so far nothing has been able to help.
Here's the link to the instructions I'm following on how to build https://wiki.documentfoundation.org/Development/BuildingOnWindows
I'm building using their suggested environment Lode on my Windows 10 machine.
I get C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h(10): error: vcruntime.h: No such file or directory
The error occurs right at the build step and I run make 2>&1 | tee build.log
I too had the same issue, but found the cause which was the Include directories were not specified correctly. To fix this I did the following with Visual Studio:
Right click on the project name, and then click on Properties.
Under Configuration Properties, select VC++ Directories.
The Include directories should contain $(VC_IncludePath);$(WindowsSDK_IncludePath); - correct this.
Click OK to save and Bob's your uncle.

MSBuild 2019 ignores INCLUDE environment variable

I am working with two machines that have Visual Studio 2019. One has Community edition, the other has Pro edition.
The pro edition of MSBuild is completely ignoring the INCLUDE environment variable, so the project I'm trying to build (ICU) cannot find stddef.h. The stddef.h file is in the Windows Kits 10 ucrt directory, which is included in the INCLUDE env var.
The community edition doesn't do this.
When I build the project with the /v:diag option I can see most of what's defined in the INCLUDE env var is added to a variable named CAExcludePath.
Here's the INCLUDE env var: INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.24.28314\include;;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.24.28314\atlmfc\include;;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\VS\include;;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt;;;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\VS\UnitTest\include;C:\Program Files (x86)\Windows Kits\8.1\Include\um;C:\Program Files (x86)\Windows Kits\8.1\Include\shared;C:\Program Files (x86)\Windows Kits\8.1\Include\winrt;;
And here's the CAExcludePath: CAExcludePath=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.24.28314\atlmfc\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.24.28314\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt;;C:\Program Files (x86)\Windows Kits\8.1\Include\um;C:\Program Files (x86)\Windows Kits\8.1\Include\shared;C:\Program Files (x86)\Windows Kits\8.1\Include\winrt;;
Why does this happen and how do I prevent it?
MSBuild 2019 ignores INCLUDE environment variable
I think you should not set these paths into Environment Variables. For C++ projects, VS does not recognize the library path in system environment variables by default and this is not the VS job.
Usually, you should set extra library paths in VS IDE. Right-click on your project-->Properties-->Configuration Properties-->VC++ Directories-->Include Directories or Properties-->Configuration Properties-->C/C++-->Additional Include Directories. You can refer to this official document.
However, when l install Windows Kits tool, this path is included in the include path by default and you can use this in your code directly. See this:
So l am afraid you have something wrong when you install the Windows Kits tool. Please follow this document to install the right tool and before you finish it, please install the related extension which is the last step in the installer in Visual Studio 2019 to integrate the tool.
I think when you install the extension, these paths will be included into VS automatically and you can use them directly.
Besides, if you do not want to install this extension, you can add the include path manually by the steps I mentioned above.
If you have done these steps and still faced the same error, I think you should check your Environment and follow these suggestions:
1) close VS Instance, delete .vs, bin, obj folders,reopen your project and then build again
2) do a repair in VS Installer
3) if your VS is not the latest, please update your VS and do not forget to update Operation System at the same time.
Hope these help.
Use the IncludePath environment variable instead.
set IncludePath=%INCLUDE%
IncludePath is not ignored/overwritten when running msbuild, and I was able to successfully compile my project/solution by setting it.
On my machine, setting IncludePath overrides 3 paths which would otherwise be set. The 3 paths have analogs (same header files but for different versions) in my %INCLUDE% paths, so it seems safe (and in fact prudent) to ignore/clobber/leave these out.

"Cannot open source file" for header files of installed SDK

I am trying to continue to work on a C++ project that somebody else started. To open the project, I had to install the C/C++ workload; I did that and already restarted my PC.
The project originally targeted a different Windows SDK version than the one that is installed on my PC. This lead to Visual Studio IntelliSense telling me "Cannot open source file" for SDK header files like stdio.h or string.h for example.
I went to the project settings > VC++ Directories > Include Directories > Edit and saw that the variables expanded to the wrong paths. Thus I proceeded to retarget the project to the Windows SDK version that is currently installed on my PC (10.0.17763.0).
Now, if I check the Include Directories, I see that "Inherit from parent or project defaults" is checked, the inherited value is
$(VC_IncludePath)
$(WindowsSDK_IncludePath)
and that this expands to
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\atlmfc\include
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\VS\include
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\winrt
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\cppwinrt
C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\Include\um
I checked that all of these directories do exist on my machine.
However, VS keeps telling me that it cannot open the source files, even after cleaning and rebuilding the whole solution. The project seems to compile, but the code is all squiggly.
My includes are:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <float.h>
#include <string.h>
#include <stdarg.h>
#include <limits.h>
#include <locale.h>
#include "svm.h"
Only stdarg.h, limits.h (both from C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\) and svm.h (in project) work. All other includes have this error; they all come from the directory C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt, I can find all of them in that directory.
I noticed that when I type #include < and let IntelliSense suggest includes, it also does not suggest those from any of the C:\Program Files (x86)\Windows Kits\10\ subdirectories. These header files are listed in the "External Dependencies" project node though.
StackOverflow is full of questions about this error, but usually about a third party lib or project file, and the answers suggest to check the Include Directories. I did that, and they appear to be complete if I can trust the expanded value, but apparently something is still wrong.
I am basically new to C++ and all the "header magic", so it might be related to the project. I found that the project contains some "stdafx.h" file (which is as I read for precompiled headers), however the project settings say to not use precompiled headers and indeed I cannot see any *.pch file either.
Encouraged by Ted Lyngmo's comment I started to edit one of the imports, when suddenly all errors disappeared and the problem was resolved, although nothing had changed.
I had done that before and it didn't help then, so unfortunately I don't know why it helped the second time. As unsatisfactory as it is - it seems that this was a caching issue after all that even persisted after clean and rebuild.
Maybe the difference was that the second time I edited was after the clean and rebuild of the solution, but I can't guarantee.
I'm not very happy with this outcome, because I would've liked to understand what helped and why, but in the end this solved the problem. So it seems you have to retarget, then clean, then rebuild, maybe restart VS, and edit some imports to force whichever cache there is to be invalidated.
P.S.: Also, in the mean time, go and participate in StackOverflow. Apparently this helps. Thus I'm marking this as community answer.

Compiling Microsoft CRT 11 (msvcrt110.dll) - What is the correct order of includes?

I am trying to compile the Microsoft CRT 11 by myself (The version that comes along with VS2012).
I'm aware that until VS2008 this action was completely supported by Microsoft:
http://msdn.microsoft.com/en-us/library/k9a8ehy3(v=vs.90).aspx
But since VS2010 you are not supposed to do it anymore, and I'm aware of the risks (mainly - compiling it wrong, and having problems that you can't figure or solve)
I'm using the following directories that come with VS as input code and header files:
Code:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\crt\src
Headers:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include
C:\Program Files (x86)\Windows Kits\8.0\Include\shared
C:\Program Files (x86)\Windows Kits\8.0\Include\um
C:\Program Files (x86)\Windows Kits\8.0\Include\WinRT
(So far the only changes I have made are to remove some MSIL sources from the project)
Most of the code compiles already. But I can't compile the file
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\crt\src\assert.c
Because of the error:
error C3861: '_ReturnAddress': identifier not found
If I add
#include <intrin.h>
it is solved. But I think it's supposed to be solvable without direct changes to the code.
Of course I'm constantly facing new challenges. But I think the solution to the current one is to fix the include order of the header directories. In which order should the header directories be used?
You can force an include (without changing the source code) in the visual studio project (although I'm not sure if it's a better solution).
To do so, right click on the .c in the solution explorer then go in C/C++ -> Advanced -> Force Include File and add intrin.h (or add /FI"intrin.h" in the command line).