visual studio 2015 doesn't see the header - c++

I'm trying to compile project connected with drivers, but VS doesn't see the header files ntddk.h and vadefs.h. I've found both of them located in:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\km
added them in projects properties:
but it stil doesn't work..

You've got a $ before the path, so it's getting confused and treating it as if you want a macro called $C:\Program which you don't have. Just use this:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\km\;%(AdditionalIncludeDirectories)

Related

Clang doesn't know PTRDIFF_MAX?

I'm upgrading our build machine (from Windows Server 2008 to Windows 10) and have a build that ran fine on the old machine (using Visual Studio). I had some problems getting it to run with VS Build Tools (I'm trying to avoid needing a VS license) on the new machine, so I'm porting it to use Clang.
The build uses Flatbuffers, which I have upgraded from 1.4.0 to 1.12.0. I'm getting the following error during the build:
[2/70] Building CXX object CMakeFiles\polyphemus.dir\hardwareconfig.cpp.obj
FAILED: CMakeFiles/polyphemus.dir/hardwareconfig.cpp.obj
C:\PROGRA~2\MICROS~1\2019\BUILDT~1\VC\Tools\Llvm\x64\bin\clang-cl.exe /nologo -TP -I"C:\Program Files (x86)\nanomsg\include\nanomsg" -I. -I"C:\Program Files (x86)\FlatBuffers\include" -IE:\JenkinsMIDEBLD\workspace\btaylor-new_build_node_CYC-268_2\polyphemus\include /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd /showIncludes /FoCMakeFiles\polyphemus.dir\hardwareconfig.cpp.obj /FdCMakeFiles\polyphemus.dir\polyphemus.pdb -c E:\JenkinsMIDEBLD\workspace\btaylor-new_build_node_CYC-268_2\polyphemus\hardwareconfig.cpp
In file included from E:\JenkinsMIDEBLD\workspace\btaylor-new_build_node_CYC-268_2\polyphemus\hardwareconfig.cpp:3:
In file included from .\hardwareconfig_generated.h:7:
In file included from C:\Program Files (x86)\FlatBuffers\include\flatbuffers/flatbuffers.h:20:
In file included from C:\Program Files (x86)\FlatBuffers\include\flatbuffers/base.h:45:
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\include\algorithm(37,63): error: use of undeclared identifier 'PTRDIFF_MAX'
return static_cast<ptrdiff_t>(_Min_value(static_cast<_CT>(PTRDIFF_MAX), static_cast<_CT>(_Value)));
Not having PTRDIFF_MAX defined is really rather odd, and suggests that Flatbuffers should have done #include <cstdint> in its files, but hasn't. This seems like something that would cause tests to fail, so I can't believe that's an undiagnosed bug. Sure enough, if I add #include <cstdint> to my files, they start building. This really doesn't seem like the correct solution though - I can't believe that Flatbuffers has an undocumented dependency that you have to do that import yourself, which suggests I'm doing something wrong. Does anyone know what, please?
EDIT: Explicitly turning on C++17 in cmake (and from there in clang) results in the same error in a different place that doesn't involve flatbuffers:
In file included from E:\JenkinsMIDEBLD\workspace\btaylor-new_build_node_CYC-268_2\polyphemus\complexseries.cpp:2:
In file included from E:\JenkinsMIDEBLD\workspace\btaylor-new_build_node_CYC-268_2\polyphemus\include\polyphemus/complexseries.h:4:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\include\complex:12:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\include\sstream:11:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\include\istream:11:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\include\ostream:11:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\include\ios:11:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\include\xlocnum:16:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\include\streambuf:11:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\include\xiosbase:12:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\include\system_error:14:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\include\stdexcept:12:
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\include\xstring(1258,47): error: use of undeclared identifier 'PTRDIFF_MAX'
return _Min_value(static_cast<size_t>(PTRDIFF_MAX), static_cast<size_t>(-1) / sizeof(_Elem));
That's in a file where I'd done my own #include of , so I guess that's a red herring (and also not a fix :-/ ).
Turned out that I had in my include path a version of stdint.h that specifies it was for use "only with Microsoft Visual C++ compilers!". Unsurprisingly, it turns out it doesn't work with Clang. You'd expect it to either fail catastrophically or else just work anyway (it does define PTRDIFF_MAX), but I guess it just causes Clang to be very very confused.
Anyway, if I remove it from my include path, things start working.

std::filesystem doesn't work in DLL project

I feel sorta silly asking this question, but I just cannot find a solution anywhere on the internet.
Notes:
I am using VS2019
C++17 is enabled
My problem is the following:
I want to iterate files in a directory with std::filesystem. To do so, I need to use the directory_iterator. However, when I include the filesystem library, it doesn't find the directory_iterator, so I checked the filesystem header file. It threw me a bunch of errors. I also cannot use experimental/filesystem because for some reason the path class also has errors which make the string functions unusable.
However, when I create a fresh console application, it works fine for me. No errors, directory_iterator has been found, I can iterate without issues.
Here is a small snippet of what the errors I'm being given when trying to compile:
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(917,28): warning C4003: not enough arguments for function-like macro invocation 'concat'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(921,1): error C2365: '_InIt': redefinition; previous definition was 'template parameter'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(921): message : see declaration of '_InIt'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(921,1): error C2061: syntax error: identifier '_First_InIt'

Update visual studio 2017, now getting compile error C7510: 'Callback': use of dependent template name must be prefixed with 'template'

I tried compiling my project as usual after the update (15.8.0). I set showincludes to yes to figure out where the error originates, but it's all system code. Starting with stdafx.cpp, it goes through all the includes and errors out:
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\pshpack8.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\poppack.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\pshpack8.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\poppack.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\winrt\wrl\event.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\winrt\eventtoken.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\pshpack8.h
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\winrt\wrl\event.h(316): error C7510: 'Callback': use of dependent template name must be prefixed with 'template'
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\winrt\wrl\event.h(324): error C7510: 'Callback': use of dependent template name must be prefixed with 'template'
Has anyone seen this before? I googled up and down to find an answer to no avail. Short of modifying the windows sdk, not sure what to do.
Edit:
In my installed windows SDK, the error was in the file-
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\winrt\wrl\event.h
Changed line 316: return DelegateHelper::Traits::Callback(Details::Forward(callback));
to: return DelegateHelper::Traits::template Callback(Details::Forward(callback));
and line 324: return DelegateHelper::Traits::Callback(
to return DelegateHelper::Traits::template Callback(Details::Forward(callback));
Since modifying an sdk is not really a solution, Peng Du's solution by selecting non conformance in the configuration window is the way to go.
I have legacy projects and I compared the project settings side by side, finally I successfully built the new project by setting: Configuration Properties > C/C++ > Language > Conformance mode = No
When you use a dependent template name, you have to use a template keyword, for example:
foo.template bar<T>();
Till some moment MSVC was not strict about using typename and template disambiguators, but after an update the rules have changed.
The problem is in the Windows Runtime Library and some change to Visual Studio broke it. I have the same issue on this laptop which is updated to 15.8.2, my machine at home running an earlier version does not do this, since the exact same code compiles on my other machine, it's got to be a bug in VS, or a change required in WRL/event class.
EDIT: Fix to the return values above worked, bug is in the SDK, you should NOT disable /permissive- as this enables protection against Spectre and other security enhancements.

Can't load a dll file in R using dyn.load windows 7 64bit

Although similar questions have been asked I can't seem to find the answer to mine. I need to include C++ code into R to speed up my algorithm. After my first attempts of understanding how it works failed, I am following this tutorial. I use dev C++ which should have the right compiler gcc(I learned that I should not be using virtual C++) and have succesfully created the .dll file that he is talking about in 1.3.2. However when i try loading it in R (64bit) I get the error message
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'C:/Rpackages/Test/src/Xdemo.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
I learned from other posts that this could due to the fact that in my path there is some calling to 32bit applications. However I removed these, but still get the same error. My path:
C:\Program Files\R\R-2.14.1\bin;C:\Rtools\bin;C:\Rtools\MinGW\bin;C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin;C:\Program Files (x86)\HTML Help Workshop;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;c:\Program Files\WIDCOMM\Bluetooth Software\;c:\Program Files\WIDCOMM\Bluetooth Software\syswow64;c:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Users\anne\AppData\Local\Smartbar\Application\;C:\Users\anne\AppData\Local\Smartbar\Application\
Some help would be really appreciated!
When I use 64bit R, the path is under ...R\R-'version'\bin\x64 (instead of \bin) and the problem goes away.
Try to use R --version to confirm.

Identify which file has included some particular header file

Sometimes with a complex header structure it happens some header is included, but it is hard to tell where from.
Is there some tool (depedency viewer?) or a method how to find the "inclusion stack" (which source / which header / which header / ...) is including one particular header file?
If the header file is included multiple times, finding first inclusion is sufficient, finding all inclusions is a welcome bonus.
Someone has posted about it but I can't find this answer.
So, In VS, go to your project properties. Choose Configuration Properties / C/C++ / Advanced / Show Includes and set "yes".
then compile you cpp file. It looks like this:
cpp file:
#include <stdio.h>
int main()
{
return 0;
}
In the output window after compiling you will see:
1>------ Build started: Project: stlport_project, Configuration: Release Win32 ------
1>Compiling...
1>stlport_project.cpp
1>Note: including file: D:\src\hrs_rt_059.00\HRS\modules\src\libs\src\external\stlport\5.1.7\stdio.h
1>Note: including file: D:\src\hrs_rt_059.00\HRS\modules\src\libs\src\external\stlport\5.1.7\stl/_prolog.h
1>Note: including file: D:\src\hrs_rt_059.00\HRS\modules\src\libs\src\external\stlport\5.1.7\stl/config/features.h
and so on
EDIT: reference to the same question Displaying the #include hierarchy for a C++ file in Visual Studio
The header you are searching for may not be directly included into the source file. You need to 'preprocess_only' the code. This can be done in g++ by using the -E option; I don't know enough about visual C to know what the exact specification is there but if you look in the help for 'preprocess' you may come up with something.
A somewhat hacky approach (but one which should work on any platform/toolchain, without needing a separate dependency analyser) is simply to add a #error at the top of the included header - you will then get a compilation error from the first .cpp file which includes it.
Visual Studio /showIncludes
Directly in the Visual Studio I have found an option called /showIncludes - the output is textual only, but indented in a way which makes reading it quite easy:
Note: including file: /*..path.anonymized..*/\TCMalloc\windows\config.h
Note: including file: /*..path.anonymized..*/\memalloc\tcmalloc\windows/port.h
Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\windows.h
Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\include\excpt.h
Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\include\crtdefs.h
Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\include\sal.h
Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\include\vadefs.h
Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\include\stdarg.h
Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\windef.h
Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winnt.h
Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\include\ctype.h
Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\include\crtdefs.h
ProFactor Include Manager
There is also a VS add-in called Include Manager which seems to provide the needed functionality in a very nice visual way.