can a directx executable be statically linked such that the redistributable dll's are not needed on the system?

1.1k views Asked by At

Please can anyone tell me if it's possible to statically link in all the directx libs.
Basically can i build an exe that will run on any windows system that does not have the directx redistribu installed?

2

There are 2 answers

0
MooseBoys On

No, the DirectX redist binaries are not available as static libs, though most of the useful functionality is now available as source in the DirectX Tool Kit.

0
Chuck Walbourn On

As noted, you can't statically link the "DirectX" libraries i.e. Direct3D, DirectInput, DirectSound, etc. That said, depending exactly on your definition of "any Windows system" you actually do not need the DirectX "Redist". It doesn't do what you think it does. See Not So DirectSetup for the a longer discussion of this.

If you use Direct3D 9 or later, DirectDraw, DirectSound 8, DirectInput 8, DirectShow, DirectMusic, DirectPlay, etc. i.e. what historically has been called "DirectX 9.0c" (aka the Summer 2004 release), those bits are always present on Windows starting with Windows XP Service Pack 2, Windows Server 2003 Service Pack 1, and Windows XP x64 Edition. Therefore, as long as you require those as your minimum OS (or something greater), you don't need any DirectX Redist because it doesn't actually install any of those things. Take a look at What's in a version number? for examples of the "you must be this high to ride this ride" checks that guarantee this. Supporting Windows 2000, Windows 9x, or Windows ME or even Windows XP RTM/SP1 these days seems way out of scope.

For Direct3D 11, read Direct3D 11 Deployment for Game Developers. Direct3D 11.0 is built into Windows 8.x and Windows 7. It is on Windows Vista Service Pack 2 with KB 971644 installed which was pushed by Windows Update so it's basically everywhere.

Where it gets murky is if you are using other stuff in the DirectX SDK:

  • All versions of D3DX9, D3DX10, and D3DX11 are deprecated (see MSDN). If you depend on these, you still need the legacy DirectSetup. The good news is that with Direct3D 11, you don't need to use it at all. Instead see Living without D3DX for a bunch of new support libraries that are statically linked to your application as well as available shared-source--which includes DirectX Tool Kit mentioned in the other answer.

  • The HLSL compiler is not actually in D3DX anymore, and if you use the Windows 8.x SDK version of D3DCompile you can deploy that DLL side-by-side with your application avoiding the need for the DirectX Redist. See HLSL, FXC, and D3DCompile. Note that this DLL only supports Windows Vista or later, so runtime HLSL compilation on Windows XP still requires the legacy DirectX SDK and DirectX Redist. If you pre-build your shaders and are not using the Effects (FX) framework, this is not an issue.

  • If you use XINPUT, you should use XINPUT 9.1.0 (the original version) unless you are specifically using the headset audio features of XInput 1.3. This version is built into Windows Vista and later. If you require Windows 8.0 or later, you can use XInput 1.4. See XINPUT and Windows 8. Note that Server editions of Windows do not have XInput 9.1.0 or 1.4.

  • If you are using XAUDIO2, then you have a choice to make. If you require Windows 8.0 or later, then you can use XAudio 2.8 as it's built-in to the OS. Otherwise you need to use XAudio 2.7 which still requires the legacy DirectX REDIST to deploy. See XAudio2 and Windows 8.

  • If you use XACT, then you have to use the legacy DirectX REDIST as that's the only way to deploy the XACT engine.

  • If you are using the legacy DirectX Managed Assemblies for .NET 1.1, you should move to something else like SlimDX or SharpDX for a host of reasons. See DirectX and .NET

If you are making use of other "DirectX" things, you should read DirectX SDKs of a certain age for some guidance. In short: Don't use Direct3D Retained Mode, DirectPlay Voice, or DirectX 7/8 Visual Basic 6.0 as they aren't in the OS starting with Windows Vista.