From 7810fe2e1fa56564004838dbd2e6928ac916eff6 Mon Sep 17 00:00:00 2001 From: Suyash Date: Fri, 18 Sep 2026 02:43:31 +0000 Subject: [PATCH] fix(win): build with MinGW-w64 and on case-sensitive filesystems MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Windows target only ever built under MSVC: - `#include ` — the MinGW-w64 header is `bluetoothapis.h`, and the case also matters when cross-compiling from a case-sensitive filesystem. - `#pragma comment(lib, ...)` is MSVC-only, so ws2_32/rpcrt4/bthprops were never linked anywhere else: ~25 undefined references to closesocket, WSAStartup, UuidFromStringA, BluetoothFindFirstRadio and friends. - `#include "Windows.h"` in WindowsGUI.h fails the same way. Link the import libraries from CMake instead, keep the pragmas for MSVC only, and move NOMINMAX/WIN32_LEAN_AND_MEAN to the target so every translation unit gets them, not just CrossPlatformGUI.cpp. Verified by cross-compiling the Windows target with x86_64-w64-mingw32-g++ 13. MSVC is unaffected: it keeps both the pragmas and the CMake libraries. Co-Authored-By: Claude Opus 5 --- Client/CMakeLists.txt | 10 +++++++-- Client/windows/WindowsBluetoothConnector.h | 24 ++++++++++++++-------- Client/windows/WindowsGUI.h | 2 +- Client/windows/main.cpp | 1 + 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Client/CMakeLists.txt b/Client/CMakeLists.txt index 9695cef9..7b42c151 100644 --- a/Client/CMakeLists.txt +++ b/Client/CMakeLists.txt @@ -84,7 +84,10 @@ if (LINUX) endif () if (WIN32) - ADD_DEFINITIONS(-DUNICODE) + target_compile_definitions(SonyHeadphonesClient PRIVATE + UNICODE _UNICODE + NOMINMAX + WIN32_LEAN_AND_MEAN) target_sources(SonyHeadphonesClient PRIVATE windows/WindowsGUI.cpp @@ -94,8 +97,11 @@ if (WIN32) imgui/backends/imgui_impl_win32.cpp ) + # Non-MSVC toolchains have no #pragma comment(lib, ...), so name every import library here. target_link_libraries(SonyHeadphonesClient - PRIVATE d3d11 + PRIVATE d3d11 dxgi d3dcompiler + ws2_32 rpcrt4 bthprops + dwmapi # imgui_impl_win32.cpp ) endif () diff --git a/Client/windows/WindowsBluetoothConnector.h b/Client/windows/WindowsBluetoothConnector.h index 824b8e1d..d6f9b855 100644 --- a/Client/windows/WindowsBluetoothConnector.h +++ b/Client/windows/WindowsBluetoothConnector.h @@ -1,17 +1,25 @@ #pragma once -#include -#pragma comment(lib, "ws2_32.lib") -#pragma comment(lib, "rpcrt4.lib") -#pragma comment(lib, "Bthprops.lib") + +// winsock2.h must precede windows.h, which bluetoothapis.h pulls in. #include #include -#include -#include +// Lowercase: the MinGW-w64 headers are named this way, and so is the file on a +// case-sensitive filesystem (cross-compiling from Linux). +#include #include -#include "IBluetoothConnector.h" + +#include #include + +#include "IBluetoothConnector.h" #include "ByteMagic.h" -#include + +// Only MSVC understands these; every other toolchain gets the libraries from CMake. +#ifdef _MSC_VER +#pragma comment(lib, "ws2_32.lib") +#pragma comment(lib, "rpcrt4.lib") +#pragma comment(lib, "bthprops.lib") +#endif class WindowsBluetoothConnector final : public IBluetoothConnector { diff --git a/Client/windows/WindowsGUI.h b/Client/windows/WindowsGUI.h index b4be8e49..0a764eb4 100644 --- a/Client/windows/WindowsGUI.h +++ b/Client/windows/WindowsGUI.h @@ -18,7 +18,7 @@ #include -#include "Windows.h" +#include #include "CrossPlatformGUI.h" diff --git a/Client/windows/main.cpp b/Client/windows/main.cpp index fd248713..cd164c5a 100644 --- a/Client/windows/main.cpp +++ b/Client/windows/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "WindowsBluetoothConnector.h" #include "CommandSerializer.h"