Cannot open include file: 'ntddk.h'
Asked Answered
R

6

16

I'm been trying to get into driver development (queue the "don't do that") I have been looking at this msdn page and after installing the WDK (Windows Driver Kit) 10 I am still unable to compile the example that they use on that page.

I have looked at other SO questions but I am unable to find the installed directory of the WDK. When I attempt to run the setup I am greeted by this: WDK Setup image

How can I solve this?

Rivarivage answered 3/3, 2016 at 16:39 Comment(9)
Firstly - is the file on your computer - use the search utility to find the ntddk.h file. Generally you need to configure your project to point to the DDK - this is a project configuration. You've not provided a lot of information barring 'the DDK seems to be installed' here.Trunnel
Sorry, I should've mentioned that searching for the file yields no result. I find this weird since it says the WDK is installed.Rivarivage
You missed the first thing you see when you look through SO questions. The title. @HansPassantRivarivage
I had to manually trawl for the file, but it was in c:\program files (x86)\Windows Kits\10\Include\10.0.10586.0\km. You're probably missing some settings in the example to get it to workTrunnel
You're a god send @Petesh I have no idea why this does not show up when I search for it even. Thank you!Rivarivage
It seems to be a quite common issue. The "sample driver" created by VS is expected to be ready to compile, but it isn't :-(Tui
@Petesh: I have exactly the same problem, my guess is there is a bug in latest WDK installer. But your workaround works, it could become an official answer instead of a simple comment (and I'd vote for it)Tui
This appears to be a serious problem with the latest WDK. I installed 10.0.14393.0 (fresh) and even creating an empty kernel mode driver project fails to set up the include directories properly. Hand crafting it doesn't seem to help either as it complains about 10.0.14393.0 not being installed. Or have any of you had any luck..?Conjugated
..I think there's something foobared; I tried to install the 10.0.14393.0 Windows SDK (not the WDK) and it failed claiming "insufficient privileges" - and that's running as Admin. Something ain't right I tell you...Conjugated
A
22

You need to add WDK headers path to your vcxproj include directories:
vcxproj properties -> C/C++ -> General -> Additional Include Directories

C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\km\

P.S.: Make sure you install SDK 10 together with WDK 10.
P.P.S: Without SDK you will get Cannot open include file: 'ntdef.h' error

Accidental answered 10/11, 2016 at 13:35 Comment(1)
You're hard-coding your SDK path, which is not automation-friendly for remote build systems.Pak
A
4

Solved it by selecting a different "Windows SDK Version" in Visual Studio under Project Properties -> General.

In the directory C:\Program Files (x86)\Windows Kits\10\Include I have 5 folders with Windows SDKs. The newest (10.0.17763.0) did not have a km subfolder. After changing the Windows SDK Version from 10.0.17763.0 to 10.0.17134.0 in Visual Studio the ntddk.h header was found.

Argybargy answered 16/6, 2019 at 13:40 Comment(0)
F
3

Rule of thumb

When you need to build with the latest (or specific) version of WDK, check that corresponding version of Win SDK is installed.

Suspected cause

In process of debugging the issue it appeared that (because of SDK version) build process was setting $(LatestTargetPlatformVersion) to 10.0.10586. While the installed WDK provides needed versions of build files only for 10.0.14393 version. Looks like this is somewhat intended behavior.

My case

In my case it was due to different versions of Win SDK and WDK. I had SDK 10.0.10586 and WDK 10.0.14393. Installing SDK 10.0.14393 solved the issue for me.

Side note

Win SDK gets installed with default layout of VS2015, but for some reason it doesn't get updates in process of VS updates.

Fruitcake answered 9/11, 2016 at 9:44 Comment(1)
The versions of the WSDK and WDK don't always match.Pak
Z
2

There is a macros $(DDK_INC_PATH) that can be added to include directories of your project (vcxproj properties -> VC++ Directories -> Include Directories)

Zedekiah answered 20/7, 2018 at 10:19 Comment(1)
how is this macro focusing? I noticed in my case, that it was pointing to a version which did not have the subfolder KMPaternity
C
1

I also faced the similar problem. Below worked for me:

Step 1: Aware of Targeted Windows Platform for which you are going to develop driver. You can check 'Windows Version' on your system by looking at Settings->System->About->Windows Specification

Windows Specification

Step 2: Make sure you install compatible "Windows SDK" and "WinSDK" matchingto targeted windows platform version.

Step 3: Verify "ntddk.h" exists at $(DDK_INC_PATH). This pre-processor macro typically evaluates to "C:\Program Files (x86)\Windows Kits\10\Include\\km". If you do not see 'km' folder then carefully follow the links mentioned in step 2 above.

"km" folder availability

Step 4: Verify Project Properties -> Configuration Properties -> General -> Platform Toolset is using "WindowsKernelModeDriver" .

Platform Toolset

Clavicytherium answered 3/1, 2020 at 11:40 Comment(0)
P
1

In case you try to build on a new system, then perhaps first try to retarget the solution to that system

enter image description here

If this does not work then look for the subfolder KM - mentioned in some of the above explanations and then try to retarget to that version, by changing the $(LatestTargetPlatformVersion)

enter image description here

Hopefully then you should beable to build with the ntddk.h file NB! Keep in mind that this will force your solution to build to that specific platform and if you try to build on another, then you will have to manually change it again. A better solution would be to make some sort of pre-build step which takes care of missing SDK and installs it, however I do not have such a solution - any one ?

Paternity answered 17/3, 2020 at 7:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.