From 2471001648cbc12462f0754a5e1c4b0db414c7b7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 19 May 2026 21:25:44 +0000 Subject: [PATCH 1/2] Initial plan From 8a8b080edbbdf75fc081538624aa45b279c430aa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 19 May 2026 21:28:42 +0000 Subject: [PATCH 2/2] Fix LNK4006 duplicate symbol warning in Windows static CMake builds Replace `#ifndef hidapi_winapi_EXPORTS` guard in windows/hid.c with `#ifndef HIDAPI_CMAKE_V0_BUILD`, and define HIDAPI_CMAKE_V0_BUILD as a PRIVATE compile definition on the hidapi_winapi CMake target. When building with CMake, hidapi_descriptor_reconstruct.c is compiled as a separate translation unit. The old guard relied on hidapi_winapi_EXPORTS which is only set for shared (DLL) builds, causing the file to be compiled twice in static builds and producing a benign-but-noisy LNK4006 warning. The new HIDAPI_CMAKE_V0_BUILD define is set for all CMake builds (both shared and static), so hid.c never #includes the .c file when using CMake. Legacy build systems that don't define HIDAPI_CMAKE_V0_BUILD continue to work as before because hid.c still #includes the file in that case. Agent-Logs-Url: https://github.com/libusb/hidapi/sessions/a624aff3-07ad-401b-8587-87bc5203841b Co-authored-by: Youw <5939659+Youw@users.noreply.github.com> --- windows/CMakeLists.txt | 6 ++++++ windows/hid.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index c8228bc84..d230c703b 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -22,6 +22,12 @@ target_link_libraries(hidapi_winapi PUBLIC hidapi_include ) +target_compile_definitions(hidapi_winapi + # CMake compiles hidapi_descriptor_reconstruct.c as a separate translation unit, + # so hid.c must not #include it (to avoid duplicate symbol LNK4006 in static builds). + PRIVATE HIDAPI_CMAKE_V0_BUILD +) + if(NOT BUILD_SHARED_LIBS) target_compile_definitions(hidapi_winapi # prevent marking functions as __declspec(dllexport) for static library build diff --git a/windows/hid.c b/windows/hid.c index 1e27f10a4..705847e0b 100644 --- a/windows/hid.c +++ b/windows/hid.c @@ -1607,7 +1607,9 @@ HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev) return last_global_error_str; } -#ifndef hidapi_winapi_EXPORTS +#ifndef HIDAPI_CMAKE_V0_BUILD +/* Include the descriptor reconstruction code when NOT building with CMake. + CMake builds compile hidapi_descriptor_reconstruct.c as a separate translation unit. */ #include "hidapi_descriptor_reconstruct.c" #endif