Reputation: 165
I'm trying to learn DirectX 11 and currently working on lighting. I need to add a Directional light to the scene, but when I set up my LightHelper.h file, it refuses to compile. It throws the error X1507 "failed to open source file: Windows.h".
I've tried uninstalling the Windows SDK and reconfiguring some of the include options to no avail. Here is my code for the header file.
#pragma once
#include <Windows.h>
#include <DirectXMath.h>
struct DirectionalLight
{
DirectionalLight()
{
ZeroMemory(this, sizeof(this));
}
DirectX::XMFLOAT4 Ambient;
DirectX::XMFLOAT4 Diffuse;
DirectX::XMFLOAT4 Specular;
DirectX::XMFLOAT3 Direction;
float Pad;
};
struct Material
{
Material()
{
ZeroMemory(this, sizeof(this));
}
DirectX::XMFLOAT4 Ambient;
DirectX::XMFLOAT4 Diffuse;
DirectX::XMFLOAT4 Specular;
DirectX::XMFLOAT4 Reflect;
};
This isn't the only header file (of course) with Windows.h, but all of the others link with no issues... I've been trying to figure it out for a couple days now. It's rather annoying.
Thanks
Edit: These are the solutions I tried.
I also tried finding the direct file path in "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\". It just threw another error about not being able to include another header from Windows.h. I think it was "excpt.h"
Upvotes: 0
Views: 1630
Reputation: 41127
With Visual C++ 2015, you are using either the Windows 8.1 SDK (by default) or the Windows 10 SDK. In both cases, you already have DirectXMath, D3DCompile, and other Direct3D headers in your path as well as the FXC
shader compiler as those are in the standard Windows SDKs.
If you need to use legacy components like D3DX11, you can add the legacy DirectX SDK paths but you should do so after the standard paths, not before, in the VC++ Directories properties.
$(VC_IncludePath);$(WindowsSDK_IncludePath);$(DXSDK_DIR)Include
$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;$(DXSDK_DIR)Lib\x86
$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;$(DXSDK_DIR)Lib\x64
See Where is the DirectX SDK? and Where is the DirectX SDK (2015 Edition)?.
Of course, ideally you'd just avoid the legacy DirectX SDK all together. See Living without D3DX
UPDATE: Note if you need D3DX9, D3DX10, and/or D3DX11 only you can also get those headers/libs/DLLS directly from NuGet rather than dealing with the mess of installing/using the legacy DirectX SDK. See this blog post.
Upvotes: 1
Reputation: 180145
When you added the DirectX header, you changed the header search path to that of DirectX. That shouldn't have been a change, you should have added the path to the existing list. You effectively removed the path to Windows.h
Upvotes: 0