|
| 1 | +--- |
| 2 | +name: Fix Missing libhidapi.0.dylib at Runtime on macOS |
| 3 | +overview: "" |
| 4 | +todos: |
| 5 | + - id: fix-hidapi-install |
| 6 | + content: Add elseif(APPLE) install rule for hidapi_darwin LIBRARY in CMakeLists.txt install block |
| 7 | + status: completed |
| 8 | +--- |
| 9 | + |
| 10 | +# Fix Missing libhidapi.0.dylib at Runtime on macOS |
| 11 | + |
| 12 | +## Problem |
| 13 | + |
| 14 | +When running `./build/install/emotiv_lsl`, macOS's dynamic linker (`dyld`) fails because it cannot find `libhidapi.0.dylib`. |
| 15 | + |
| 16 | +**Root cause:** The binary has these RPATHs embedded: |
| 17 | + |
| 18 | +- `@executable_path/../Frameworks` |
| 19 | +- `@executable_path/Frameworks` |
| 20 | +- `@executable_path` |
| 21 | + |
| 22 | +The dylib `libhidapi.0.dylib` exists in the build tree at `build/_deps/hidapi-build/src/mac/libhidapi.0.dylib` (with install name `@rpath/libhidapi.0.dylib`), but the `cmake --install` step never copies it to `build/install/`. The install directory only contains `emotiv_lsl` and `LSLTemplate.cfg`. |
| 23 | + |
| 24 | +On Windows, this is already handled in [CMakeLists.txt](CMakeLists.txt) (lines 206–208): |
| 25 | + |
| 26 | +```cmake |
| 27 | +if(WIN32) |
| 28 | + install(TARGETS hidapi_winapi RUNTIME DESTINATION "${INSTALL_BINDIR}") |
| 29 | +endif() |
| 30 | +``` |
| 31 | + |
| 32 | +But there is no equivalent `elseif(APPLE)` branch. |
| 33 | + |
| 34 | +## Fix |
| 35 | + |
| 36 | +Add a macOS install rule for the `hidapi_darwin` shared library target in [CMakeLists.txt](CMakeLists.txt), inside the `EMOTIVLSL_BUILD_EMOTIV` install block (lines 202–209). |
| 37 | + |
| 38 | +Since `INSTALL_BINDIR` is `.` on macOS, this places `libhidapi.0.dylib` alongside `emotiv_lsl`, satisfying the `@executable_path` RPATH entry. |
| 39 | + |
| 40 | +The changed block will look like: |
| 41 | + |
| 42 | +```cmake |
| 43 | +if(EMOTIVLSL_BUILD_EMOTIV) |
| 44 | + install(TARGETS emotiv_lsl RUNTIME DESTINATION "${INSTALL_BINDIR}") |
| 45 | + if(WIN32) |
| 46 | + install(TARGETS hidapi_winapi RUNTIME DESTINATION "${INSTALL_BINDIR}") |
| 47 | + elseif(APPLE) |
| 48 | + install(TARGETS hidapi_darwin LIBRARY DESTINATION "${INSTALL_BINDIR}") |
| 49 | + endif() |
| 50 | +endif() |
| 51 | +``` |
| 52 | + |
| 53 | +After re-running `cmake --install build --prefix build/install`, `libhidapi.0.dylib` will be present in `build/install/` and the binary will launch successfully. |
0 commit comments