1

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.

unknowncoder
  • 43
  • 1
  • 1
  • 6
  • Have you checked that the file 'd3dx9.h' is indeed in the include path? – roalz Jan 13 '17 at 09:49
  • I have yes, and as far as I see. It really is there. – unknowncoder Jan 13 '17 at 09:52
  • What Visual Studio version are you using? Have you checked that the DirectX SDK include path is correctly picked up by your c++ project (see project properties)? – roalz Jan 13 '17 at 09:56
  • I am using Microsoft Visual studio community 2015, What exactly do you mean by being correctly picked up? How could I check this? – unknowncoder Jan 13 '17 at 10:01
  • Where did you exactly added "In my Include Directories" the d3d SDK path? – roalz Jan 13 '17 at 10:23
  • Under project properties in VC++ Directories there is Include Directories, Thats where I linked the path to the file. – unknowncoder Jan 13 '17 at 10:26
  • Go and install [Process Monitor](https://technet.microsoft.com/en-us/sysinternals/processmonitor.aspx) and do a build and filter cl.exe. You'll see it try to open d3dx9.h from all the include paths it knows about - this will very likely tell you exactly why it doesn't find it. – Mike Vine Jan 13 '17 at 10:33
  • I will go and give that a shot Mike, will let you know what it tells me. – unknowncoder Jan 13 '17 at 10:40
  • After a few more builds it does however show d3d9.h which for some reason does include fine without any problems. – unknowncoder Jan 13 '17 at 10:53
  • It showed a whole different path than I had in mind for d3d9.h, so I tried placing d3dx9.h in that same path. And it indeed does include correctly now! However it does still ask for another file which isn't there now so I assume i'm not meant to do it this way but rather just let it include from the directxsdk folder. Do you have any idea why it doesn't include from that folder but from : C:\Program Files (x86)\Windows Kits\8.1\Include\shared - Or should I just put every file necessary in the other folder? – unknowncoder Jan 13 '17 at 10:56
  • Note that when compiling the compiler just looks in all possible places it knows about for that file (it doesn't know which of the 10+ include directories it'll find d3dx9.h in) - dont just put the file in one of those places but try to work out why, in the list of places it DOES look for d3d9x.h, it doesn't include the one you were expecting – Mike Vine Jan 13 '17 at 11:03
  • I have fixed it, I thank you all for helping me. Process Monitor surely did help me out. Cheers. – unknowncoder Jan 13 '17 at 11:54

1 Answers1

8

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.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81