windows: fix LNK4006 duplicate symbol warning in static CMake builds #809
No reviewers
Labels
No labels
3rdparty
Android
API
Author does not respond
bsd
bug
build system/CI
ci-virtual-device
CMake
Contributions Welcome
Core
dependencies
device-specific
documentation
don't_merge
duplicate
enhancement
Example
Haiku
hidraw
hotplug
info required
invalid
libusb
macOS
Misc
Not an issue
question
Release
Test
Test GUI
Windows
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libusb/hidapi!809
Loading…
Reference in a new issue
No description provided.
Delete branch "copilot/fix-cmake-build-warnings"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When building hidapi as a static library via CMake (e.g. from hidapitester), MSVC emits a linker warning because
hidapi_descriptor_reconstruct.cis compiled twice: once as a separate CMake source and once via#includeinsidehid.c.The old guard
#ifndef hidapi_winapi_EXPORTSwas intended to prevent the double-include, buthidapi_winapi_EXPORTSis only set by MSVC for shared (DLL) builds — leaving static builds unprotected.Changes
windows/hid.c: Replace thehidapi_winapi_EXPORTSguard withHIDAPI_CMAKE_V0_BUILD:windows/CMakeLists.txt: DefineHIDAPI_CMAKE_V0_BUILDas aPRIVATEcompile definition onhidapi_winapifor all CMake builds (shared and static alike), sohid.calways skips the#includewhen building via CMake.Legacy (non-CMake) build systems remain unaffected: without the definition,
hid.ccontinues to#includethe file as before.