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

Windows10+Cygwin环境下CMake链接双SDK失败求助

Hey there, let's tackle this linker issue step by step—working with two SDKs alongside Cygwin on Windows can get tricky thanks to cross-toolchain quirks, especially as a C++ newbie. Let's break down the root causes and fix them:

First, Understand the Core Problem

The "undefined reference" errors almost certainly stem from library format incompatibility. Most Windows SDKs (like Leap Motion and Ultrahaptics) ship with MSVC-compatible .lib files by default, but Cygwin uses the GNU toolchain (GCC/ld), which requires GNU-format static libraries (.a) or import libraries (.dll.a). MSVC .lib files won't play nicely with Cygwin's linker.

Step-by-Step Fixes

1. Convert SDK Libraries to Cygwin-Compatible Format

If the SDKs don't provide pre-built GNU-format libraries, you'll need to convert their dynamic libraries (.dll) to Cygwin import libraries:

  • For each SDK's .dll (e.g., Leap.dll, Ultrahaptics.dll):
    1. First, export a .def file listing the DLL's symbols. You can do this with MSVC's dumpbin (run from an MSVC Command Prompt):
      dumpbin /exports C:\Path\To\Leap.dll > Leap.def
      
      Or use Cygwin's objdump if you prefer:
      objdump -p /cygdrive/c/Path/To/Leap.dll | grep -A 100 "Export Address Table" > Leap.def
      
    2. Use Cygwin's dlltool to generate a GNU-compatible import library:
      dlltool -d Leap.def -l libLeap.dll.a
      
    3. Repeat this for Ultrahaptics.dll and any dependent DLLs (like libusb-1.0.dll).

2. Fix Your CMakeLists.txt

Your current CMake config has mixed path styles and inconsistent project/target names. Let's rewrite it to be Cygwin-friendly:

cmake_minimum_required(VERSION 3.8)
project(ICMI2017Demo) # Match your target name to avoid confusion
set(CMAKE_CXX_STANDARD 11)

# --- Ultrahaptics SDK Configuration ---
set(ULTRAHAPTICS_ROOT "/cygdrive/c/Program Files/Ultrahaptics")
include_directories(${ULTRAHAPTICS_ROOT}/include)
# Point to the directory with your converted .dll.a libraries
link_directories(${ULTRAHAPTICS_ROOT}/lib/x64)
set(ULTRAHAPTICS_LIBS Ultrahaptics usb-1.0) # CMake will look for libUltrahaptics.dll.a etc.

# --- Leap Motion SDK Configuration ---
set(LEAP_ROOT "/cygdrive/c/PhD/code/libraries/LeapSDK")
include_directories(${LEAP_ROOT}/include)
link_directories(${LEAP_ROOT}/lib/x64)
set(LEAP_LIBS Leap)

# --- Source Files ---
# Don't forget to include header files used in your project
set(SOURCE_FILES 
    main.cpp 
    main.h 
    HapticSurface/LeapMotionDataConversion.hpp
)

add_executable(ICMI2017Demo ${SOURCE_FILES})

# Link the converted libraries
target_link_libraries(ICMI2017Demo ${ULTRAHAPTICS_LIBS} ${LEAP_LIBS})

3. Verify Runtime Dependencies

Even if compilation succeeds, you'll need to ensure the SDK .dll files are accessible to your executable:

  • Copy Leap.dll, Ultrahaptics.dll, and libusb-1.0.dll to the same directory as ICMI2017Demo.exe
  • Or add the SDK bin/x64 directories to your Windows PATH environment variable

4. Test Incrementally

To narrow down issues, compile a minimal test program for each SDK separately:

  • For Leap Motion: Write a tiny program that initializes the Leap controller and checks for compilation/linking
  • For Ultrahaptics: Do the same with a basic Ultrahaptics device setup
    This will confirm if one SDK is causing more issues than the other.

Quick Checks to Rule Out Simple Mistakes

  • Ensure you're using 64-bit Cygwin (match your SDK and Windows architecture)
  • Double-check that all paths in CMake use Cygwin-style syntax (/cygdrive/c/... instead of C:/...)
  • Confirm you've installed full Cygwin development tools (gcc-g++, cmake, make, dlltool, etc.)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 04:23:00