melchor629 / node-flac-bindings

Nodejs bindings to libFLAC
ISC License
17 stars 1 forks source link

macbook pro m1, 13.2 (22D49) can't load libflac #45

Closed zhushenwudi closed 1 year ago

zhushenwudi commented 1 year ago

Hello, this is my new macbook, and i found that it cant covert flac to wav correctly.

I use node-flac-bindings v2.7.2 now

error message:

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason: Error: dlopen(/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/build/Release/flac-bindings.node, 0x0001): Library not loaded: /opt/homebrew/opt/flac/lib/libFLAC.8.dylib Referenced from: /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/build/Release/flac-bindings.node Reason: tried: '/opt/homebrew/opt/flac/lib/libFLAC.8.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/flac/lib/libFLAC.8.dylib' (no such file), '/opt/homebrew/opt/flac/lib/libFLAC.8.dylib' (no such file), '/usr/local/lib/libFLAC.8.dylib' (no such file), '/usr/lib/libFLAC.8.dylib' (no such file, not in dyld cache), '/opt/homebrew/Cellar/flac/1.4.2/lib/libFLAC.8.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/flac/1.4.2/lib/libFLAC.8.dylib' (no such file), '/opt/homebrew/Cellar/flac/1.4.2/lib/libFLAC.8.dylib' (no such file), '/usr/local/lib/libFLAC.8.dylib' (no such file), '/usr/lib/libFLAC.8.dylib' (no such file, not in dyld cache) at process.func [as dlopen] (node:electron/js2c/asar_bundle:5:1800) at Object.Module._extensions..node (node:internal/modules/cjs/loader:1199:18) at Object.func [as .node] (node:electron/js2c/asar_bundle:5:1800) at Module.load (node:internal/modules/cjs/loader:988:32) at Module._load (node:internal/modules/cjs/loader:829:12) at Function.c._load (node:electron/js2c/asar_bundle:5:13331) at Module.require (node:internal/modules/cjs/loader:1012:19) at require (node:internal/modules/cjs/helpers:94:18) at bindings (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/bindings/bindings.js:112:48) at Object. (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/lib/api.js:4:13) (node:39010) UnhandledPromiseRejectionWarning: Error: dlopen(/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/build/Release/flac-bindings.node, 0x0001): Library not loaded: /opt/homebrew/opt/flac/lib/libFLAC.8.dylib Referenced from: /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/build/Release/flac-bindings.node Reason: tried: '/opt/homebrew/opt/flac/lib/libFLAC.8.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/flac/lib/libFLAC.8.dylib' (no such file), '/opt/homebrew/opt/flac/lib/libFLAC.8.dylib' (no such file), '/usr/local/lib/libFLAC.8.dylib' (no such file), '/usr/lib/libFLAC.8.dylib' (no such file, not in dyld cache), '/opt/homebrew/Cellar/flac/1.4.2/lib/libFLAC.8.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/flac/1.4.2/lib/libFLAC.8.dylib' (no such file), '/opt/homebrew/Cellar/flac/1.4.2/lib/libFLAC.8.dylib' (no such file), '/usr/local/lib/libFLAC.8.dylib' (no such file), '/usr/lib/libFLAC.8.dylib' (no such file, not in dyld cache) at process.func [as dlopen] (node:electron/js2c/asar_bundle:5:1800) at Object.Module._extensions..node (node:internal/modules/cjs/loader:1199:18) at Object.func [as .node] (node:electron/js2c/asar_bundle:5:1800) at Module.load (node:internal/modules/cjs/loader:988:32) at Module._load (node:internal/modules/cjs/loader:829:12) at Function.c._load (node:electron/js2c/asar_bundle:5:13331) at Module.require (node:internal/modules/cjs/loader:1012:19) at require (node:internal/modules/cjs/helpers:94:18) at bindings (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/bindings/bindings.js:112:48) at Object. (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/lib/api.js:4:13) (node:39010) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

image

It seem like that flac.8.dylib disappear on latest macos

melchor629 commented 1 year ago

Hello! I think you should rebuild flac-bindings with npm rebuild flac-bindings. In latest libflac version (1.4) they changed the number of the shared library:

flac changelog

(see https://xiph.org/flac/changelog.html)

Hope with the recompile is enough to have it working again :)

Lore: This is a common practice in the C/C++ libraries, to have a "binary version" in the name of the shared library. If between versions the API compatibility is broken, the number is incremented.

zhushenwudi commented 1 year ago

I delete /node_module/flac_bindings/build folder, and use npm rebuild flac-bindings to re-generate build folder. But I didn't find any node files in build/Release, so I used the make command to try to compile, but he reported a mistake

[  3%] Building CXX object CMakeFiles/flac-bindings.dir/src/mappings/frame.cpp.o
/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/src/mappings/frame.cpp:107:13: error: cannot cast from type 'const union (unnamed union at /opt/homebrew/Cellar/flac/1.4.2/include/FLAC/format.h:295:2)' to pointer type 'int32_t *' (aka 'int *')
            (int32_t*) subframe.data.verbatim.data,
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/flac-bindings.dir/src/mappings/frame.cpp.o] Error 1
make[1]: *** [CMakeFiles/flac-bindings.dir/all] Error 2
make: *** [all] Error 2

ps. I also wrote a prebuild script because I couldn't compile it before, and placed the node file from github in the built/release folder so that I could use it.

melchor629 commented 1 year ago

Mmm I see. I've been looking for the commit I made to make the library work with libflac 1.4 and just in the place where it failed, there is a breaking change (https://github.com/melchor629/node-flac-bindings/commit/f52cc88cedf0b6861a5db6efc224e19ba2269336). I see here two options:

  1. Somehow downgrade your installation of libflac to any of the 1.3 versions
  2. Remove your installation of libflac and let my package download the code of a known working version for you (it will take more time to compile but it should work).

Note that I do not have experience with M1/M2 Macs so there is maybe any other issue I didn't know. Let me know if something else does not work.

I would recommend you the second option because it will bundle libflac with your app, so you won't need to copy the library manually for distribution.

zhushenwudi commented 1 year ago

You mean, I need uninstall flac in my computer environment variable?

melchor629 commented 1 year ago

If you don't have a way to install flac 1.3, then try uninstalling flac installed on your computer. At least temporarily, just to see if compiles fine.

The build script tries to use already installed flac before trying to download and compile flac (because it is faster to use something already compiled). But in this case it seems that is causing you trouble :/

zhushenwudi commented 1 year ago

Successfully, I uninstalled flac and rebuilt flac-bindings. Unfortunately, this is an production env bug that can only be corrected in the next version, thx bro