Building with XAudio2 on Windows 7

 ̄綄美尐妖づ 提交于 2019-12-23 12:08:55

问题


I'm trying to use the following instructions to build some code that uses XAudio2 and runs on Windows 7:

http://msdn.microsoft.com/en-us/library/windows/desktop/ee663275%28v=vs.85%29.aspx

As suggested, I'm including the XAudio2.h from the DirectX SDK:

#include <%DXSDK_DIR%Include\xaudio2.h>

Result:

fatal error C1083: Cannot open include file: '%DXSDK_DIR%Include\xaudio2.h': No such file or directory

Oh well. I was pretty sure VC++ didn't expand environment variables like that anyway. So I replaced the #include with one that included it directly:

#include <C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Include/XAudio2.h>

(Some other instructions, that also suggest using the full path, can be found here: http://blogs.msdn.com/b/chuckw/archive/2012/04/02/xaudio2-and-windows-8-consumer-preview.aspx)

Result:

c:\program files (x86)\microsoft directx sdk (june 2010)\include\xaudio2.h(20): fatal error C1083: Cannot open include file: 'comdecl.h': No such file or directory

Sure enough, that file includes comdecl.h using angle brackets, directing VC++ to look outside the current folder.

I added the DirectX SDK include folder ($(DXSDK_DIR)/include) to the project #include search path then, leaving the #include as it was, and:

c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(12): warning C4005: 'DXGI_STATUS_OCCLUDED' : macro redefinition
       c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49449) : see previous definition of 'DXGI_STATUS_OCCLUDED'

(...ad infinitum)

(my project includes the DirectX headers as well.)

Same result if I added the DirectX SDK include folders to the other end of the search path list.

Has anybody managed to get any of this to work while following these (or any other) instructions?


回答1:


The XAudio2 API is now a system component in Windows 8. The headers and libraries for XAudio2 are available in the Windows SDK.

Well, the problem is that you mixing old headers from DirectX SDK and new from Win8 SDK which was not intended to use together.

Most times

warning C4005: macro redefinition

means that your code compiles and run well. But to prevent possible errors in future, you must use one of the:

  • Windows 8 SDK v110_xp toolset (Project Properties -> General -> Platform Toolset) and old DirectX SDK. There are some drawbacks: read in the bottom here
  • Windows 7 SDK v100 toolset and old DirectX SDK. You need to install Windows 7 SDK.
  • Only Windows 8 SDK v110 platform toolset.
  • Dig into headers, isolate and strip XAudio2 stuff and make it possible to use independly from any of SDKs. But this is not quite good idea =)

Edit: I edited my answer, because I found that XAudio is still not obsolete =)




回答2:


Hey sorry I know I'm late on this but this article

https://directxtk.codeplex.com/wikipage?title=Adding%20the%20DirectX%20Tool%20Kit%20for%20Audio&referringTitle=Writing%20custom%20shaders

details how you need to include the legacy includes and libs. One thing to note, as I understand it after including these directories you will then have dependencies on the Microsoft DirectX SDK (June 2010) directory which windows 8 and 10 don't have. This means when you go to package up your project you should include/run the legacy directx redist for installation on newer machines.

You've probably already solved this issue but hopefully anyone else who finds this will see this. Hope it helps!



来源:https://stackoverflow.com/questions/17097823/building-with-xaudio2-on-windows-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!