mpogue2 / SquareDesk

Fully-featured music player and sequence designer, designed for square dance callers
9 stars 4 forks source link

Bug: Missing dependencies for Vamp #1065

Open mpogue2 opened 5 months ago

mpogue2 commented 5 months ago

Vamp depends on: libsndfile/libsndfile.1.dylib libogg/lib/libogg.0.dylib libvorbis/lib/libvorbis.0.dylib libvorbis/lib/libvorbisenc.2.dylib flac/lib/libFLAC.8.dylib

When I updated home-brew, I lost the FLAC dylib, so vamp no longer runs. But, there's a bigger problem here -- all of these X86-64 dylibs should be located in Contents/MacOS, or else the app is not portable to a machine that doesn't have those libs installed via Homebrew.

Need to change the .pro file to copy these in as well. AND, I need to get a copy of the libFLAC dylib, too.

mpogue2 commented 5 months ago

Symptom: can't find sections/beats/measures anymore, after an update from Homebrew.

mpogue2 commented 5 months ago

I do have /usr/local/Cellar/flac/1.4.3/lib/libFLAC.12.dylib, but I don't have the .8 version. This was last updated with Homebrew on 2/28/2024, so this is very likely when it stopped working.

mpogue2 commented 5 months ago

It really should tell the user that something is wrong when this happens, too, rather than having things just stop working.

mpogue2 commented 5 months ago

Hint: MacDependency is my friend.

mpogue2 commented 5 months ago

OK, MacDependency says that libFLAC.12.dylib is compatible with libFLAC.8.dylib, and indeed when I do: ln -s /usr/local/opt/flac/lib/libFLAC.12.dylib /usr/local/opt/flac/lib/libFLAC.8.dylib then ./vamp-simple-host appears to start up correctly.

So, I need to do TWO things:

The latter is explained here: https://medium.com/@donblas/fun-with-rpath-otool-and-install-name-tool-e3e41ae86172 I think we want something like this done BEFORE build time, so that the build can just stick the executables into the MacOS folder and call it a day:

install_name_tool -add_rpath @executable_path/. ./vamp-simple-host

Also note that this: DYLD_PRINT_LIBRARIES=1 ./vamp-simple-host

gives us this (abridged here to just show the dependencies we need to copy in):

dyld[65848]: <86CB6382-34E7-34D3-87CF-9D3044C41E10> /usr/local/Cellar/libsndfile/1.2.2/lib/libsndfile.1.0.37.dylib
dyld[65848]: <31F54119-AFD5-3BC8-9CF3-0219B7031AB9> /usr/local/Cellar/libogg/1.3.5/lib/libogg.0.8.5.dylib
dyld[65848]: <DA7F7CAE-8D16-37D7-B52F-9988143141A1> /usr/local/Cellar/libvorbis/1.3.7/lib/libvorbis.0.dylib
dyld[65848]: <E3986D08-096C-31D1-ADE4-707F97B57C19> /usr/local/Cellar/libvorbis/1.3.7/lib/libvorbisenc.2.dylib
dyld[65848]: <8E068287-B619-344F-9E0E-AC8C071700BA> /usr/local/Cellar/flac/1.4.3/lib/libFLAC.12.dylib
dyld[65848]: <33BEFE01-AA5D-3408-84C5-D7065F2F7B90> /usr/local/Cellar/opus/1.4/lib/libopus.0.dylib
dyld[65848]: <7675B832-AFAA-3C22-B806-E81CB79BCE1E> /usr/local/Cellar/mpg123/1.32.5/lib/libmpg123.0.dylib
dyld[65848]: <B69319FA-C9B7-3A7C-A150-E511F8D792BF> /usr/local/Cellar/lame/3.100/lib/libmp3lame.0.dylib
mpogue2 commented 5 months ago

This was the download link I used to get vamp-simple-host: https://code.soundsoftware.ac.uk/projects/vamp-plugin-sdk/files

mpogue2 commented 5 months ago

This is a better reference: http://clarkkromenaker.com/post/library-dynamic-loading-mac/

mpogue2 commented 5 months ago

OK, this is going to be straightforward, but initially painful. If we redistribute the executables provided by QM (which makes sense), we need to update the library references for the executable and all the libraries, like this:

otool -l ./vamp-simple-host

gives this (excerpted):

cmd LC_LOAD_DYLIB
cmdsize 64
name /usr/local/opt/flac/lib/libFLAC.8.dylib (offset 24)
time stamp 2 Wed Dec 31 16:00:02 1969

Then run:

install_name_tool -change /usr/local/opt/flac/lib/libFLAC.8.dylib @rpath/libFLAC.8.dylib ./vamp-simple-host
otool -l ./vamp-simple-host

giving this (excerpted):

cmd LC_LOAD_DYLIB
cmdsize 48
name @rpath/libFLAC.8.dylib (offset 24)

and make sure we do this:

install_name_tool -add_rpath @executable_path/. ./vamp-simple-host
otool -l ./vamp-simple-host

giving this (excerpted):

cmd LC_RPATH
cmdsize 32
path @executable_path/. (offset 12)
mpogue2 commented 5 months ago

Also, note that libsndfile also loads libFLAC.12.dylib . So, we need to ensure that we don't have TWO copies of libFLAC included, just so we can meet dependencies.

I'm thinking that I make a separate script to do all the library rpath editing. Then, do a clean install of the binaries from QM. Run the script. Turn off /usr/local/opt entirely, and run vamp-simple-host. That should check that all the dependencies are local.

Also, DYLD_PRINT_LIBRARIES=1 ./vamp-simple-host will check this.

Its output looks like this:

dyld[70367]: <590D0ACD-3133-38B9-B15E-73E0FAB462BD> /Users/mpogue/Downloads/vamp-plugin-sdk-2.10.0-binaries-macos/vamp-simple-host
dyld[70367]: <86CB6382-34E7-34D3-87CF-9D3044C41E10> /usr/local/Cellar/libsndfile/1.2.2/lib/libsndfile.1.0.37.dylib
dyld[70367]: <31F54119-AFD5-3BC8-9CF3-0219B7031AB9> /usr/local/Cellar/libogg/1.3.5/lib/libogg.0.8.5.dylib
dyld[70367]: <DA7F7CAE-8D16-37D7-B52F-9988143141A1> /usr/local/Cellar/libvorbis/1.3.7/lib/libvorbis.0.dylib
dyld[70367]: <E3986D08-096C-31D1-ADE4-707F97B57C19> /usr/local/Cellar/libvorbis/1.3.7/lib/libvorbisenc.2.dylib
dyld[70367]: <5FAEF6CA-ADDB-34AF-9DAA-B5AFE3FD761F> /Users/mpogue/Downloads/vamp-plugin-sdk-2.10.0-binaries-macos/libFLAC.8.dylib

See that last line? Notice that the dylib is in the same place as the executable itself in the first line.

mpogue2 commented 5 months ago

OK, that was somewhat painful. I believe I have a custom version of vamp-simple-host that has "." on its search path (that I made a long time ago when I compiled it on an X86 system). That allows the .dylibs to be in the same directory as the vamp-simple-host executable.
Now all the dependencies are in there, too. There are a bunch of them.

This might be cleaned up by eliminating the ability to read anything except WAV files (the dependent libs are all different file formats, both encoders and decoders). A later opportunity for space optimization, I think.

At this point, vamp-simple-host should be self-contained now to the Contents/MacOS folder. It previously was reaching out to /usr/local/opt, requiring libsnd and ITS dependencies to be on the system... that should be fixed now, and vamp should run on both X86_64 and M1 systems (with Rosetta), even if you haven't installed libsndfile with Homebrew. I included the original dylibs from libsndfile from Homebrew, and a doit script that will fix all the library paths so that files are localized to Contents/MacOS.

Commit: 550df1d9f90d8eec37b6a15f3810cc1e5cec653e