Adding DirectX directories to Visual Studio

posted in DruinkJournal
Published January 27, 2009
Advertisement
Another one of these "I'll link this entry from various threads" posts:

Sometimes when you install the DirectX SDK, it doesn't properly add the directories to Visual Studio, so VS can't find the DirectX headers and library files. The most common symptom of this is the compile error "Cannot open include file: 'd3d9.h': No such file or directory".

To add the headers and library files to Visual Studio (2005 or 2008, they're both the same), go to the Tools menu -> Options, then go to Projects and Solutions -> VC++ Directories. First, make sure the "Show directories for:" droplist in the top right is set to "Include files", and add the path to the DirectX SDK/Include directory, and make sure it's at the top of the list by clicking the black up arrow icon:
DirectX SDK Header Files

Next, change the "Show directories for:" droplist to "Library files", and add the path to the DirectX SDK/Lib/x86 directory. The additional x86 directory is important here, and if you miss it out, Visual Studio won't be able to find the library files:
DirectX SDK Library Files
If you're building for x64, then you'll want to change the "Platform" drop list to "x64" and add the DirectX SDK/Lib/x64 directory instead. If you're not sure what you want, then you probably want Win32 and the x86 directory.

After you've added those two directories, click "OK", then hit F5 to build and run your code again.
Previous Entry Untitled
Next Entry Delays, more delays
0 likes 5 comments

Comments

Mike.Popoloski
But what if you want to compile for x64?
January 27, 2009 06:38 AM
Evil Steve
Quote:Original post by Mike.Popoloski
But what if you want to compile for x64?
Tough.

Ok, I'll edit it then [smile]. I was working on the assumption that most people who aren't sure how to set up the DirectX SDK directories won't be doing x64 compilation.
January 27, 2009 07:40 AM
SuperRad
You might want to use $(DXSDK_DIR) instead of "C:\Program files\Microsoft DirectX SDK (March 2008)" as the DXSDK_DIR environmental variable should be created when you install the DirectX SDK.
Might be a bit more useful for others with the SDK installed elsewhere :)
[edit] Forgot to say, great work on the tutorials so far, keep up the good work[/edit]
January 28, 2009 10:45 AM
Evil Steve
Quote:Original post by SuperRad
You might want to use $(DXSDK_DIR) instead of "C:\Program files\Microsoft DirectX SDK (March 2008)" as the DXSDK_DIR environmental variable should be created when you install the DirectX SDK.
Might be a bit more useful for others with the SDK installed elsewhere :)
I meant that the path you enter should be the path to wherever you installed the SDK. Personally, I think it's safer to use a direct path rather than an environment variable, since if the directories weren't added in the first place, there's a change the environment variables weren't set up properly either. It's just a little safer.

Quote:Original post by SuperRad
[edit] Forgot to say, great work on the tutorials so far, keep up the good work[/edit]
Thanks, I hope to get the next one up soon [smile]
January 29, 2009 04:55 AM
Amr0
Hi Steve. For VC++ 2010 (Express and Pro it seems), the VC++ Directories section in the preferences is gone, and the directories are now supposed to be set on a per-project basis. This can be resolved by following these steps. Also see this post and the replies to it for additional infos. I'm posting this in case you want to update this useful entry of yours to be more complete. Salutes.
October 28, 2010 03:28 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement