From 059fd721babe9cf6f7daf1018b3cb73146e34a0a Mon Sep 17 00:00:00 2001 From: Misaki Date: Mon, 26 Oct 2026 14:47:19 +0800 Subject: [PATCH] fix: link static ElaWidgetTools on Windows Propagate ELAWIDGETTOOLS_LIBRARY to consumers when the Windows build uses the static ElaWidgetTools library. This avoids dllimport symbols such as __imp_ZN7ElaMenu... under MinGW. Document the stale-build workaround. --- README.md | 3 +++ client/CMakeLists.txt | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index f7e5351..8d970dd 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,9 @@ cmake --build --preset linux-gcc `windows-mingw` 使用 Ninja,并显式指定 `gcc.exe` / `g++.exe` / `windres.exe`, 不会退回 MSVC。测试 preset 使用 `QT_QPA_PLATFORM=offscreen`,不需要桌面会话。 + 若出现 `undefined reference to __imp__ZN...ElaMenu...` / `ElaScrollBar`,说明仍在把 + 静态 ElaWidgetTools 当作 DLL 客户端;本仓库会在 Windows 静态构建时自动向使用方传播 + `ELAWIDGETTOOLS_LIBRARY`。删除 `build/windows-mingw` 后重新 configure 即可。 4. 运行: ```powershell diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 6e075b6..bfcd91e 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -41,6 +41,14 @@ if(NOT MSVC) # 第三方库内部仍使用少量 Qt 已弃用 API,抑制其告警但不修改其源码。 target_compile_options(ElaWidgetTools PRIVATE -Wno-deprecated-declarations) endif() +if(WIN32 AND ELAWIDGETTOOLS_BUILD_STATIC_LIB) + # ElaProperty.h 默认把使用方当作动态库客户端(dllimport)。静态链接时必须让 + # 使用方也看到 ELAWIDGETTOOLS_LIBRARY,否则 MinGW 会生成 __imp_ 前缀符号。 + target_compile_definitions(ElaWidgetTools INTERFACE ELAWIDGETTOOLS_LIBRARY) + if(MSVC) + target_compile_options(ElaWidgetTools INTERFACE /wd4251 /wd4275) + endif() +endif() add_subdirectory(src) add_subdirectory(tests)