Skip to content

Commit 283f7cf

Browse files
committed
2 parents 1bf74e0 + fa4e08f commit 283f7cf

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ if(EMOTIVLSL_BUILD_EMOTIV)
205205
)
206206
if(WIN32)
207207
install(TARGETS hidapi_winapi RUNTIME DESTINATION "${INSTALL_BINDIR}")
208+
elseif(APPLE)
209+
install(TARGETS hidapi_darwin LIBRARY DESTINATION "${INSTALL_BINDIR}")
208210
endif()
209211
endif()
210212

@@ -225,7 +227,7 @@ if(APPLE)
225227
FRAMEWORK_DESTINATION "${INSTALL_BINDIR}/${PROJECT_NAME}.app/Contents/Frameworks"
226228
)
227229
endif()
228-
if(LSLTEMPLATE_BUILD_CLI)
230+
if(LSLTEMPLATE_BUILD_CLI OR EMOTIVLSL_BUILD_EMOTIV)
229231
LSL_install_liblsl(FRAMEWORK_DESTINATION "Frameworks")
230232
endif()
231233
else()

0 commit comments

Comments
 (0)