Cannot open source file d3dx9.h

unknowncoder picture unknowncoder · Jan 13, 2017 · Viewed 16.4k times · Source

Before I start off I know this is quite a common question, I did search for answers before posting here. Unfortunately, I had no luck.

In my code I include the file like this:

#include <d3dx9.h>

Now the error shows up: Cannot open source file d3dx9.h

In my Include Directories I did enter the path to where it is (if I look it up manually through my files, I can see it there).

The path is: C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include

I also set the Library Directory: C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x64

x64 since I am running a 64 bit system.

I'd highly appreciate it if someone could take the time to post a suggestion.

Greetings.

Answer

Chuck Walbourn picture Chuck Walbourn · Jan 14, 2017

Visual Studio 2015 includes the Windows 8.1 SDK which is newer than the headers in the legacy DirectX SDK. The Windows 8.1 SDK includes all the DirectX headers and libraries, but does not contain the now deprecated D3DX (D3DX9, D3DX10, D3DX11) utility library which is why it is "missing".

D3DX9, D3DX10, and D3DX11 are only available in the legacy DirectX SDK. With VS 2010, the VC++ Directory settings you were supposed to use were as follows for Win32 (x86) settings:

<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x86;$(LibraryPath)</LibraryPath>

and this for x64 native:

<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x64;$(LibraryPath)</LibraryPath>

With VS 2012 or later, you have to reverse them since most of the headers in the Windows 8 SDK replace the older DirectX SDK:

<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x86</LibraryPath>

and

<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x64;</LibraryPath>

See MSDN, Where is the DirectX SDK (2015 Edition)?, The Zombie DirectX SDK, and Not So Direct Setup.

With all that said, you probably shouldn't be using legacy Direct3D 9 anyhow. Using DirectX 11 with one of the modern replacements for D3DX is a better, cleaner option and doesn't require the legacy DirectX SDK. See Living without D3DX.

If you are specifically targeting to run a program on Windows XP SP3 with Direct3D 9, you'll be using the v140_xp Platform Toolset which uses the Windows 7.1A SDK, not the Windows 8.1 SDK. Therefore, you go with the old-school include order. See this post for details.