Fix Windows build issues with newer MinGW
Subsystems (2)
v2 cover Fix Windows build issues with newer MinGW
From: Nguyen Dinh Phi <[email protected]>
This series fixes build issues when compiling QEMU on Windows with newer MinGW-w64 toolchains.
Patch 1 addresses a redefinition error for ConvertStringToBSTR(), which is now provided by newer MinGW versions in <comutil.h>.
Patch 2 relocates qemu_ftruncate64() to a more appropriate location.
Nguyen Dinh Phi (2):
qga/vss-win32: Fix ConvertStringToBSTR redefinition with newer MinGW
util: Move qemu_ftruncate64 from block/file-win32.c to oslib-win32.c
block/file-win32.c | 32 -------------------------------- meson.build | 12 ++++++++++++ qga/vss-win32/install.cpp | 2 ++ util/oslib-win32.c | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 32 deletions(-)
---
V2:
- Use links() instead of compiles() to dectect the definition of ConvertStringToBSTR() in meson.build
Signature · 1 line
2.43.0
PATCH v2 1/2 qga/vss-win32: Fix ConvertStringToBSTR redefinition with newer MinGW
From: Nguyen Dinh Phi <[email protected]>
Newer versions of MinGW-w64 provide ConvertStringToBSTR() in the _com_util namespace via <comutil.h>. This causes a redefinition error when building qemu-ga on Windows with these toolchains.
Add a meson check to detect whether ConvertStringToBSTR is already available, and conditionally compile our fallback implementation only when the system does not provide one.
--- meson.build | 12 ++++++++++++ qga/vss-win32/install.cpp | 2 ++ 2 files changed, 14 insertions(+)
meson.build +12 -0
@@ -3299,6 +3299,18 @@ endif # Detect host pointer size for the target configuration loop. host_long_bits = cc.sizeof('void *') * 8 +# Detect if ConvertStringToBSTR has been defined in _com_util namespace +if host_os == 'windows' + has_convert_string_to_bstr = cxx.links(''' + #include <comutil.h> + int main() { + BSTR b = _com_util::ConvertStringToBSTR("test"); + return b ? 0 : 1; + } + ''') + config_host_data.set('CONFIG_CONVERT_STRING_TO_BSTR', has_convert_string_to_bstr) +endif + ######################## # Target configuration # ########################
qga/vss-win32/install.cpp +2 -0
@@ -549,6 +549,7 @@ STDAPI DllUnregisterServer(void) /* Support function to convert ASCII string into BSTR (used in _bstr_t) */ +#ifndef CONFIG_CONVERT_STRING_TO_BSTR namespace _com_util { BSTR WINAPI ConvertStringToBSTR(const char *ascii) {
@@ -566,6 +567,7 @@ namespace _com_util return bstr; } } +#endif /* Stop QGA VSS provider service using Winsvc API */ STDAPI StopService(void)
Signature · 1 line
2.43.0
Re: [PATCH v2 1/2] qga/vss-win32: Fix ConvertStringToBSTR redefinition with newer MinGW
Quoted 65 lines · On Thu, Dec 18, 2025 at 10:55 AM <[email protected]> wrote:
From: Nguyen Dinh Phi <[email protected]>
Newer versions of MinGW-w64 provide
ConvertStringToBSTR()in the_com_utilnamespace via <comutil.h>. This causes a redefinition error when building qemu-ga on Windows with these toolchains.Add a meson check to detect whether ConvertStringToBSTR is already available, and conditionally compile our fallback implementation only when the system does not provide one.
Signed-off-by Nguyen Dinh Phi <[email protected]>Suggested-by Pierrick Bouvier <[email protected]>--- meson.build | 12 ++++++++++++ qga/vss-win32/install.cpp | 2 ++ 2 files changed, 14 insertions(+)meson.build +12
-0@@ -3299,6 +3299,18 @@ endif # Detect host pointer size for the target configuration loop. host_long_bits = cc.sizeof('void *') * 8 +# Detect if ConvertStringToBSTR has been defined in _com_util namespace +if host_os == 'windows' + has_convert_string_to_bstr = cxx.links(''' + #include <comutil.h> + int main() { + BSTR b = _com_util::ConvertStringToBSTR("test"); + return b ? 0 : 1; + } + ''') + config_host_data.set('CONFIG_CONVERT_STRING_TO_BSTR', has_convert_string_to_bstr) +endif + ######################## # Target configuration #########################
qga/vss-win32/install.cpp +2
-1@@ -549,6 +549,7 @@ STDAPI DllUnregisterServer(void) /* Support function to convert ASCII string into BSTR (used in _bstr_t) */ +#ifndef CONFIG_CONVERT_STRING_TO_BSTR namespace _com_util { BSTR WINAPI ConvertStringToBSTR(const char *ascii) {@@ -566,6 +567,7 @@ namespace _com_util return bstr; } } +#endif /* Stop QGA VSS provider service using Winsvc API */ STDAPI StopService(void) --2.43.0
Re: [PATCH v2 1/2] qga/vss-win32: Fix ConvertStringToBSTR redefinition with newer MinGW
In reply to [email protected]Quoted 10 lines · On 12/18/25 12:54 AM, [email protected] wrote:
From: Nguyen Dinh Phi <[email protected]>
Newer versions of MinGW-w64 provide
ConvertStringToBSTR()in the_com_utilnamespace via <comutil.h>. This causes a redefinition error when building qemu-ga on Windows with these toolchains.Add a meson check to detect whether ConvertStringToBSTR is already available, and conditionally compile our fallback implementation only when the system does not provide one.
Quoted 6 lines
Signed-off-by Nguyen Dinh Phi <[email protected]>Suggested-by Pierrick Bouvier <[email protected]>--- meson.build | 12 ++++++++++++ qga/vss-win32/install.cpp | 2 ++ 2 files changed, 14 insertions(+)
Thanks for the update,
PATCH v2 2/2 util: Move qemu_ftruncate64 from block/file-win32.c to oslib-win32.c
In reply to [email protected]From: Nguyen Dinh Phi <[email protected]>
qemu_ftruncate64() is a general-purpose utility function that may be used outside of the block layer. Move it to util/oslib-win32.c where other Windows-specific utility functions reside.
--- block/file-win32.c | 32 -------------------------------- util/oslib-win32.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 32 deletions(-)
block/file-win32.c +0 -32
@@ -170,38 +170,6 @@ static BlockAIOCB *paio_submit(BlockDriverState *bs, HANDLE hfile,return thread_pool_submit_aio (aio_worker, acb, cb, opaque); } -int qemu_ftruncate64 (int fd,int64_t length) -{ -LARGE_INTEGER li; -DWORD dw; -LONG high; -HANDLE h; -BOOL res; - -if ((GetVersion () &0x80000000UL ) && (length >>32 ) !=0 ) -return -1 ; - - h = (HANDLE )_get_osfhandle (fd); - -/* get current position, ftruncate do not change position */ - li.HighPart =0 ; - li.LowPart =SetFilePointer (h,0 , &li.HighPart,FILE_CURRENT ); -if (li.LowPart ==INVALID_SET_FILE_POINTER &&GetLastError () !=NO_ERROR ) { -return -1 ; - } - - high = length >>32 ; - dw =SetFilePointer (h, (DWORD ) length, &high,FILE_BEGIN ); -if (dw ==INVALID_SET_FILE_POINTER &&GetLastError () !=NO_ERROR ) { -return -1 ; - } - res =SetEndOfFile (h); - -/* back to old position */ -SetFilePointer (h, li.LowPart, &li.HighPart,FILE_BEGIN ); -return res ?0 :-1 ; -} -static int set_sparse (int fd) {DWORD returned;
util/oslib-win32.c +34 -0
@@ -899,3 +899,37 @@ int qemu_shm_alloc(size_t size, Error **errp)error_setg (errp,"Shared memory is not supported." );return -1 ; } + +int qemu_ftruncate64 (int fd,int64_t length) +{ +LARGE_INTEGER li; +DWORD dw; +LONG high; +HANDLE h; +BOOL res; + +if ((GetVersion ()&0x80000000UL ) && (length >>32 ) !=0 ) { +return -1 ; + } + + h = (HANDLE )_get_osfhandle (fd); + +/* get current position, ftruncate do not change position */ + li.HighPart =0 ; + li.LowPart =SetFilePointer (h,0 , &li.HighPart,FILE_CURRENT ); +if (li.LowPart ==INVALID_SET_FILE_POINTER &&GetLastError () !=NO_ERROR ) { +return -1 ; + } + + high = length >>32 ; + dw =SetFilePointer (h, (DWORD ) length, &high,FILE_BEGIN ); +if (dw ==INVALID_SET_FILE_POINTER &&GetLastError () !=NO_ERROR ) { +return -1 ; + } + res =SetEndOfFile (h); + +/* back to old position */ +SetFilePointer (h, li.LowPart, &li.HighPart,FILE_BEGIN ); +return res ?0 :-1 ; +} +
Signature · 1 line
2.43.0
Re: [PATCH v2 2/2] util: Move qemu_ftruncate64 from block/file-win32.c to oslib-win32.c
Hi,
Quoted 11 lines · On 18/12/25 09:54, [email protected] wrote:
From: Nguyen Dinh Phi <[email protected]>
qemu_ftruncate64()is a general-purpose utility function that may be used outside of the block layer. Move it toutil/oslib-win32.cwhere other Windows-specific utility functions reside.Signed-off-by Nguyen Dinh Phi <[email protected]>--- block/file-win32.c | 32 -------------------------------- util/oslib-win32.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 32 deletions(-)
If not change, please keep the previous tags so we don't have to review again and again the same patch:
Regards,
Phil.