DirectX11 release VS 2010 C++ - c++

I compiled my code in VS C++ 2010. If I use debug version, everything is okay!
If I want to make release version, I've got communicat:
main.cpp(7): fatal error C1083: Cannot open include file: 'd3dx11.h': No such file or directory
I use DirectX 11. What should I do?

As noted on MSDN, all versions of D3DX are deprecated including D3DX9, D3DX10, and D3DX11. You can certainly continue to use the deprecated libraries by using the legacy DirectX SDK. Remember that with VS 2010, you have to manually add the include/lib paths to your VC++ Directories properties page of your project to use the DirectX SDK with it.
For 32-bit Win32 configurations:
$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)
$(DXSDK_DIR)Include;$(IncludePath)
$(DXSDK_DIR)Lib\x86;$(LibraryPath)
For x64 native configurations:
$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)
$(DXSDK_DIR)Include;$(IncludePath)
$(DXSDK_DIR)Lib\x64;$(LibraryPath)
If you were able to get #include <d3dx11.h> to work for DEBUG builds, but not RELEASE, you probably failed to set the VC++ Directories for All Configurations / All Platforms.
Another option would instead be to move to VS 2012 or VS 2013 which includes the Windows 8.x SDK which has the DirectX SDK integrated into it. There you'd make use of DirectX Tool Kit, DirectXTex, DirectXMesh, and/or other replacements for legacy D3DX.
Note if you were making use of the legacy DirectX SDK to continue to use D3DX11 and were also using the Windows 8.x SDK (such as with VS 2012 or VS 2013), then you'd have to reverse the include order above because the legacy DirectX SDK headers are older than the ones in the Windows 8.x SDK.
$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x86
$(IncludePath);$(DXSDK_DIR)Include
$(LibraryPath);$(DXSDK_DIR)Lib\x86
For x64 native configurations:
$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86
$(IncludePath);$(DXSDK_DIR)Include
$(LibraryPath);$(DXSDK_DIR)Lib\x64
Note you can get the Windows 8.1 SDK and DirectX Tool Kit to work with VS 2010 as noted here, but if you can I'd highly recommend using the VS 2013 Community edition if you don't have the budget for VS 2013 Professional or better.

Related

How to compile C++ app for Windows XP in MSVS?

As I read this article, it is enough to download most recent MSVS 2022 and then install toolset C++ Windows XP Support for VS 2017 (v141) tools [Deprecated].
After that in Visual Studio inside project properties I set this toolset. According to linked article it is enough to compile C++ app with XP support.
But after my .exe file is created if I run it on XP 64-bit SP2 then it shows error that CompareStringEx function is not found in KERNEL32.DLL.
Hence it appears that it is not enough to use this toolset. Something else is needed.
In some other places I see that one needs also to add define /D_USING_V110_SDK71_ when compiling and option /SUBSYSTEM:CONSOLE,5.01 when linking. In my project properties I also tried to add this two options, but still CompareStringEx is inside import table of final application.
As suggested by #BenVoigt, I did defines /DWINVER=0x0502 /D_WIN32_WINNT=0x0502. Also set C++ standard to /std:c++14 (I would set C++11 but this MSVS version allows to set only C++14 at minimum). Still some non-XP symbols remain in final EXE like InitializeSRWLock that is possibly used by C++11's std::mutex in my code.
Does anyone know everything what is needed in order to compile fully XP-compatible application?
Update. I managed to build working XP application by doing things above plus setting C++ CRT runtime to Multi Threaded DLL, i.e. using dynamic DLL linkage of CRT. Also as suggested by #ChuckWalbourn (down x86 or x64 redists), I downloaded older version of msvcp140.dll.
But it is very important for my project to have statically linked runtime (C++ CRT), i.e. use Multi Threaded value for Runtime field in project properties. Only if it is REALLY not possible only then I will use DLL CRT. Until then solution about how to link CRT statically are welcome, of course to produce XP-compatible EXE.
TL;DR For Window XP VC++ REDIST support, install https://aka.ms/vs/15/release/VC_redist.x86.exe on your Windows XP system
-or-
if you are doing "side-by-side application local deployment", then use the DLLs from C:\Program Files\Microsoft Visual Studio\2022\<edition>\VC\Redist\MSVC\14.16.27012\x86\Microsoft.VC141.CRT.
If you want the latest bug fixes to the CRT, you can also download the REDIST for VS 2019 (16.7) per the link on Microsoft Docs.
For Windows XP targeting, you use the v141_xp Platform Toolset installed by Visual Studio (VS 2017, VS 2019, or VS 2022) which is the latest VS 2017 (v141) C++ compiler using an included Windows 7.1A SDK.
Make sure you have installed (for VS 2022) the following individual components since you are using MFC:
Microsoft.VisualStudio.Component.WinXP: C++ Windows XP Support for VS 2017 (v141) tools [Deprecated]
Microsoft.VisualStudio.Component.VC.v141.x86.x64: MSVC v141 - VS 2017 C++ x64/x86 build tools (v14.16)
Microsoft.VisualStudio.Component.VC.v141.MFC: C++ MFC for v141 build tools (x86 & x64)
If you are doing DirectX development, be sure to read this blog post as well for various implications of using the Windows 7.1A SDK.
For deployment to Windows XP, you can install the latest VS 2017 Visual C++ REDIST or use VS 2019 Visual C++ up to VS 2019 (16.7). After that the REDIST DLLs themselves are not compatible with Windows XP.
On your development system with VS 2022 installed, you are going to have a newer set of Visual C++ REDIST files which are binary compatible with your v141_xp Platform Toolset built EXE, but those VC++ REDIST DLLs are not compatible with Windows XP.
IOW: If you look at a dumpbin /imports of the 14.30 (v143 version), 14.29 (v142 latest version), and/or 14.16 (v141 latest version ) copies of msvcp140.dll you will see different imports. The msvcp140.dll sitting in your C:\windows\SysWOW64 folder is going to be the 14.30 version.

Cannot open source file d3dx9.h

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.
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.

How to install Visual Studio Build Tools 2010 on Visual Studio 2015 Community?

I have a project created on Visual Studio 2010. When I try to run the project on Visual Studio 2015 Community edition I get the error below,
Severity Code Description Project File Line
Error MSB8020 The build tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, please install Visual Studio 2010 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". graphics C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets 55
And when I tried to build it with Visual Studio 2015 Build Tools I encountered about 1500+ errors.
Is there any way to make the project work?
If you can't install VS2010, Windows SDK for Windows 7 contains needed compiler tools (v100), you may actually skip installing the SDK itself and install only the compiler tools, headers and libs. Please note, that the compiler included in Windows SDK is the same that VS2010 has, but VS2010 SP1 has a bit newer compiler. If you need that, you'll also need to install Microsoft Visual C++ 2010 Service Pack 1 Compiler Update for the Windows SDK 7.1. But be aware, that if you install these, you may have issues later if you decide to install VS2010, there are bugs in installer that requires you to install components in strict order. Also, if your code uses MFC or ATL you must install VS2010, installing Windows SDK will not be enough.
You either install VS 2010 and build your project, or better yet you upgrade your projects. The VS 2015 custom install options will let you install the v120 Platform Toolset, but not the v110 or v100 Platform Toolsets.
One major change in VS 2015 is that the C++ tools (i.e. v140) are not installed by the Typical installation option. See the Visual C++ Team Blog.
Keep in mind that Visual C++ 2010 used the C++0x Draft Standard, and Visual C++ 2015 meets the C++11 Standard with the exception of Expression SFINAE (which is partly there in Update 1), so quite a bit has changed in the intervening years including some breaking changes. Since you are jumping three major releases at once--and about 10 minor updates--, it can be a bit overwhelming especially working through all the new warnings.
Another thing to keep in mind is that Visual C++ 2010 used the Windows 7.1 SDK, while Visual C++ 2012 or later use the Windows 8.x SDK. There's been a lot of change there too particularly for DirectX development. It's particularly important for Windows desktop apps that you set the _WIN32_WINNT preprocessor define for your target platform as the Windows 8.x SDK does not default to the 'oldest supported platform' like earlier Windows SDKs did. See Using the Windows Headers
VS 2010 and the v100 toolset supports targeting Windows XP and Windows Server 2003. The v140 toolset does not support targeting Windows XP / Server 2003. You have to use v140_xp Platform Toolset instead. See this post for some notes as this means you are again using the Windows 7.1 SDK rather than the Windows 8.x SDK with the _xp toolsets.
See Breaking Changes in Visual C++ 2012, Breaking Changes in Visual C++ 2013, and Breaking Changes in Visual C++ 2015.
See also Support For C++11/14/17 Features (Modern C++), and Where is the DirectX SDK?.
If you need to build the code both with VS 2010 and with VS 2015, then you should create two projects/solution files, one for each. You may also want to read this article for some notes on writing code that can build with multiple Visual C++ toolsets, which again is particularly challenging due to the Windows SDK changes.
VS 2015 supports targeting Windows Vista SP2, Windows 7 SP1, Windows 8.0, Windows 8.1, Windows 10, and optionally Windows XP SP3. It does not support targeting Windows Vista RTM, Windows Vista SP1, or Windows 7 RTM.

Where can I find 'winmm.lib' (I'm using Visual Studio 2012)

My OS is 64Bit Windows 7.
I wanted to build the DirectX Sample in
C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Samples\C++\Direct3D10\Tutorials\Tutorial02.
but when I build error occured with fatal error
LNK1104: 'winmm.lib' can't open the file.
I reinstalled Direct SDK, but no change. I also added the path (include, lib) to the settings.
If I remove 'winmm.lib' from the project settings, 'comctl32.lib' can't be opened.
both libs were already present in properties>Linker>Input.
How can I solve this problem?
Just put the line below in stdafx.h
#pragma comment(lib, "winmm.lib")
winmm.lib isn't part of the DirectX SDK but is part of the Windows SDK.
Latest Windows SDK versions were also heavily reorganized but it includes the library you're looking for.
If you are trying to build any of the legacy DirectX SDK samples with VS 2012 or VS 2013, you need to modify the include/libs paths per the instructions on bottom of the page on MSDN. The most important change is that you must reverse the Include/Lib path order:
For VS 2010 it was:
$(DXSDK_DIR)Include;$(IncludePath)
$(DXSDK_DIR)Lib\x86;$(LibraryPath) or $(DXSDK_DIR)Lib\x64;$(LibraryPath)
For VS 2012/2013 it has to be:
$(IncludePath);$(DXSDK_DIR)Include
$(LibraryPath);$(DXSDK_DIR)Lib\x86 or $(LibraryPath);$(DXSDK_DIR)Lib\x64
Of course a better option is not spend time learning the older Direct3D 10 API at all, and use the latest Direct3D 11 Win32 desktop tutorials on MSDN Code Gallery. In fact, I've posted many of the legacy DirectX SDK samples there so they work fine with VS 2012/2013 Express for Windows Desktop and VS 2012/2013 Pro+ as-is without the DirectX SDK at all.
Read these blog posts:
DirectX SDK Samples Catalog
DirectX SDK Tools Catalog
Living without D3DX
DirectX SDKs of a certain age
And review these CodePlex projects:
DirectX Tool Kit
DirectXMesh
DirectXTex
DXUT for Direct3D 11
Effects 11

directx 9 cannot find the include libraries

I wanna start learning DirectX in Visual C++ 2010, but it says that d3dx11 and d3dx9 can't be found when I include d3dx9.h, I can play games in DirectX 11 and dxdiag says my computer is running directX 11, but when I searched for DirectX 11 in C drive and my D-Drive, it couldn't find anything. So I decided to install DirectX 11 and then I got a folder after installing, but it didn't have any include or bin folders, so I couldn't go to properties and VC++ and add the include directories. Decided to try DirectX 9 instead to start with, but when I installed DirectX 9 June 2010 version, I went to C\Microsoft DirectX SDK (June 2010) there is no directories, only DirectX utilities and documentation for c++ and sample browser and Command prompt. So I don't really know what to do anymore, I have tried to install d3dx9.lib and put in in the default lib folder for VS 2010. but no success, But I have DirectX 9 2004 summer libraries and Include folders set up for visual c++, but that is such an old version so it doesn't include d3dx9.lib. I'm running Windows 8.1 64 bit OS.
The DirectX SDK and all version of the D3DX libraries are both deprecated.
The 'modern' solution is to use the Windows 8.x SDK which comes with Visual Studio 2012 and Visual Studio 2013. You can install the Windows 8.1 SDK 'standalone' and use it with Visual Studio 2010 by using .props files. See MSDN and this blog post for all the details.
You can mix using the Windows 8.x SDK with the legacy DirectX SDK in order to continue to use D3DX for Win32 desktop applications--you cannot use the DirectX SDK for Windows Store apps, Windows phone, or Xbox One. See the instructions on MSDN for how to handle the include/lib path directories. If you are going to continue to use the legacy DirectX SDK, you need to be aware of a number of things:
The DirectX SDK (June 2010) installer has some compatibility issues with systems that have VS 2010 SP1 REDIST installed. See this post.
The DirectX SDK (June 2010) does not have the latest developer debug runtime for Windows 8.1. You have to install the Windows 8.1 SDK, VS 2013, or the VS 2013 remote debugging tools to get the DEBUG layers and REFERENCE device. See this post.
There is no support for the Direct3D 9 DEBUG device on Windows 8.1.
The "PIX for Windows" tool in the DirectX SDK does not work for Direct3D 10.x or Direct3D 11.x on Windows 8.1, Windows 8.0, or Windows 7 SP1 with the DirectX 11.1 Runtime installed. Use the Visual Studio 2013 Graphics Diagnostics, or Intel/AMD/NVIDIA's GPU tools.
If you are deploying a game that needs the legacy DLLs like D3DX, be sure to use the April 2011 refreshed version of DXSETUP and not the copy that is in the DirectX SDK (June 2010). See this post and be sure to read Not So DirectSetup.
Given all that, your life will be a lot easier if you just use Direct3D 11 and avoid the legacy DirectX SDK and D3DX entirely. You can find many Direct3D 11 replacements for D3DX that only requires the Windows 8.x SDK along with a bunch of updated samples. See Living Without D3DX, DirectX Tool Kit, and DirectX SDK Samples Catalog. You can get all that to work with VS 2010, but it's a lot easier to get Visual Studio 2013 Express for Windows Desktop (for Win32 desktop applications) and/or Visual Studio 2013 Express for Windows (for Windows Store apps and Windows phone apps).
PS: Even back when the DirectX SDK was still the supported way to get Direct3D headers for VS 2010, it was not available until you manually added the include/path directories to your project. That's why you can't include "d3dx9.h" in your project freshly created.