You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows平台Visual Studio 2019(MSVC)下Libusb动态链接库(DLL)损坏导致链接错误求助

Fixing LNK1107 Error with Libusb Dynamic Linking in Visual Studio 2019

Hey Leo, let's work through that frustrating LNK1107 error you're facing when trying to use dynamic linking with Libusb in VS2019. As someone who's hopped between UNIX and Windows development, I know how easy it is to trip up on Windows' linking rules. Here are targeted fixes to get your dynamic build working:

1. Stop linking directly to the .dll file (use the import .lib instead)

The most common cause of this error is trying to add the libusb-1.0.dll directly to your linker's additional dependencies. MSVC requires an import library (.lib) to link against dynamic DLLs—you can't use the DLL file itself for linking.

  • Go to your project properties → Linker → Input → Additional Dependencies
  • Replace any reference to libusb-1.0.dll with libusb-1.0.lib (this is the import library generated when you compiled Libusb's dynamic version)
  • Make sure this .lib file is from the same x64 Debug build as your project.

2. Match architecture and build type exactly

Windows is strict about matching 32-bit/64-bit and Debug/Release builds between your library and project. Mismatches often lead to "corrupted file" errors:

  • Double-check your project's configuration: Go to Build → Configuration Manager and confirm it's set to x64 Debug
  • Grab the correct files from your Libusb build output:
    • Import lib: libusb-1.0.24\msvc\x64\Debug\libusb-1.0.lib
    • DLL (for runtime): libusb-1.0.24\msvc\x64\Debug\libusb-1.0.dll
  • Copy the DLL to your project's output directory (usually your-project\x64\Debug) so it's found at runtime.

3. Clean and rebuild everything to eliminate stale cache

Sometimes leftover build artifacts from static linking attempts can cause conflicts. A full clean ensures you're using fresh, matching files:

  • Open the Libusb VS2019 solution, select x64 Debug, right-click the project → Clean, then Rebuild
  • Do the same for your own project: Right-click → Clean, then Rebuild

4. Ensure the LIBUSB_SHARED macro is defined

For dynamic linking to work correctly, both Libusb and your project need to define the LIBUSB_SHARED preprocessor macro. This tells the compiler to generate code compatible with dynamic libraries:

  • In your project properties → C/C++ → Preprocessor → Preprocessor Definitions, add LIBUSB_SHARED (if it's not already there)
  • Verify Libusb's dynamic build has this macro enabled (it should be set by default in the VS project for dynamic configurations)

5. Avoid third-party DLLs—stick to your compiled version

DLLs from random third-party sites are risky: they might be outdated, modified, or compiled with different settings that clash with your environment. Always use the DLL you compiled yourself from the official Libusb source—it's the only way to guarantee compatibility.

Give these steps a shot, and let me know if any of them resolve your issue. If you're still stuck, sharing a screenshot of your linker settings or the exact paths you're using for the library files could help narrow things down further.

内容的提问来源于stack exchange,提问作者leoK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 20:22:51