From: Hraban Luyat Date: Wed, 2 Nov 2016 16:05:51 +0000 (+0000) Subject: Dynamic linking explanation X-Git-Tag: v2.0.0~45 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=3d5fe8ad3e7510e9358d5351fcf26e625b19120b;p=go-opus.git Dynamic linking explanation --- diff --git a/README.md b/README.md index 3cb63c3..7dca3c7 100644 --- a/README.md +++ b/README.md @@ -138,9 +138,35 @@ Mac: brew install pkg-config opus opusfile ``` -Note that this will link the opus libraries dynamically. This means everyone who -uses the resulting binary will need to have opus and opusfile installed (or -otherwise provided). +### Linking libopus and libopusfile + +The opus and opusfile libraries will be linked into your application +dynamically. This means everyone who uses the resulting binary will need those +libraries available on their system. E.g. if you use this wrapper to write a +music app in Go, everyone using that music app will need libopus and libopusfile +on their system. + +The obvious way to do this is to publish your software through a package manager +and specify libopus and libopusfile as dependencies of your program. If that is +not an option, you can compile the dynamic libraries yourself and ship them with +your software as seperate (.dll or .so) files. + +On Linux, for example, you would need the libopus.so.0 and libopusfile.so.0 +files in the same directory as the binary. Set your ELF binary's rpath to +`$ORIGIN` (this is not a shell variable but elf magic): + +```sh +patchelf --set-origin '$ORIGIN' your-app-binary +``` + +Now you can run the binary and it will automatically pick up shared library +files from its own directory. + +Wrap it all in a .zip, and ship. + +I know there is a similar trick for Mac (involving prefixing the shared library +names with `./`, which is, arguably, better), and Windows... probably just picks +up .dll files from the same dir by default? I don't know. But there are ways. ## License