I want to use xaudio2 library in my Qt application for Windows 10. I use Qt creator 4.9.2 as IDE in conjuction with MinGW 7.3.0 compiler. As I know xaudio2 is a part of windows SDK, starting from Win8. I've got the latest SDK version from this page and installed it on my workstation. I import this library, by adding this lines in my .pro file:
INCLUDEPATH += "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um"
unix|win32: LIBS += -lxaudio2
And also include the needed definitions in my sources like this:
#include <xaudio2.h>
But when I try to compile my app the following error appears:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\xaudio2.h:20: error: #error "This version of XAudio2 is available only in Windows 8 or later. Use the XAudio2 headers and libraries from the DirectX SDK with applications that target Windows 7 and earlier versions."
#error "This version of XAudio2 is available only in Windows 8 or later. Use the XAudio2 headers and libraries from the DirectX SDK with applications that target Windows 7 and earlier versions."
^~~~~
I couldn't understand, why compiler doesn't identify my system as Win10, but rather Win7 instead. Also I've figured out, that only xaudio2_8.lib is present in this SDK release, but AFAIK, xaudio2_9.lib should be used on Win10.
Can anybody help me to solve this problem?
This is based on the _WINNT_WIN32
preprocessor define.
If you look in xaudio2.h, you'd see:
#if(_WIN32_WINNT < _WIN32_WINNT_WIN8)
#error "This version of XAudio2 is available only in Windows 8 or later. Use the XAudio2 headers and libraries from the DirectX SDK with applications that target Windows 7 and earlier versions."
#endif // (_WIN32_WINNT < _WIN32_WINNT_WIN8)
The _WINNT_WIN32
define has to be 0x0602
(Windows 8.0), or 0x0603
(Windows 8.1), or 0x0A00
(Windows 10) to target XAudio 2.8/2.9.
See this blog post and Microsoft Docs: Using the Windows Headers .
UPDATE: Note there is a new package to get XAudio 2.9 down-level to Windows 7 SP1 or later. See Microsoft Docs .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.