Skip to content

[Bug] Failed loading libhidapi.dylib on M1 mac due to homebrew path changed #60

@LSChyi

Description

@LSChyi

Can not compile firmware even dependencies are fulfilled.

Describe the Bug

After manually installed the osx-cross/avr/avr-gcc (which installs avr-gcc@9 at the time present) and arm-none-eabi-gcc, qmk doctor passed with just a warning about the avr-gcc version, I can run the build command on my M1 Macbook Pro. However, the build failed with just saying that

ERROR: Can not run "qmk" command!

 Please run util/qmk_install.sh to install all the dependencies QMK requires.

make: *** [phoenix:default] Error 1

After digging into the code, I found that it fails at loading the dynamic library HIDAPI, which fails at the __init__.py of the hid site package. I checked my LD_LIBRARY_PATH and the libhidapi.dylib is right there.

This happens because the homebrew path changed on M1 machines into /opt/homebrew, thus the search failed. I know this may not be the issue of qmk_cli, but there are some improvements we can make:

  1. Improve the error message without just saying ERROR: Can not run "qmk" command!, at least make the error clear with different log levels such as debug.
  2. Find a workaround for fixing this:
    • Could be setting some environment variables to make the search of dynamic library successful? I am not sure about that because looks like it is using another process without passing environment variables.
    • Document the workaround such as make a soft link pointing to the old search path.

Additional Context

I have tested by manually setting the load path to

hidapi = ctypes.cdll.LoadLibrary("/opt/homebrew/lib/libhidapi.dylib")

in /opt/homebrew/Cellar/qmk/0.0.52/libexec/lib/python3.9/site-packages/hid/__init__.py and I can compile the firmware without any problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions