Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OS X] ffi path discovery OSX #13

Closed
akhenakh opened this issue Jul 3, 2016 · 6 comments
Closed

[OS X] ffi path discovery OSX #13

akhenakh opened this issue Jul 3, 2016 · 6 comments

Comments

@akhenakh
Copy link

akhenakh commented Jul 3, 2016

I'm using Macports in OSX so most of my libs are located in /opt/local
I have to load the shared liquid dsp lib by its full path for luaradio to detect it.

lib_available, lib = pcall(ffi.load, "/opt/local/lib/libliquid.dylib")
if lib_available then
  platform.libs["liquid"] = lib
  platform.features["liquid"] = true
end

I've tried LD_LIBRARY_PATH to avoid patching with no luck, I'm not very familiar with luajit.
Thanks.

@vsergeev
Copy link
Owner

vsergeev commented Jul 3, 2016

I think in Mac OS X's case, the equivalent environment variable is DYLD_LIBRARY_PATH. Another option may be to add /opt/local/lib to Mac OS X's equivalent of /etc/ld.so.conf and rerunning Mac OS X's equivalent of sudo ldconfig... Unfortunately, I don't have a Mac to test on.

@akhenakh
Copy link
Author

akhenakh commented Jul 3, 2016

tried DYLD_FALLBACK_LIBRARY_PATH & DYLD_LIBRARY_PATH with no result.
Thanks for the tip anyway

@vsergeev vsergeev changed the title ffi path discovery OSX [OS X] ffi path discovery OSX Jul 4, 2016
@rht
Copy link

rht commented Oct 16, 2016

You could manually set LDFLAGS to include -L/opt/local/lib and/or CFLAGS/CPPFLAGS to include -I/opt/local/include. Though this could be set in macports config as well.

@n7ihq
Copy link

n7ihq commented Nov 29, 2016

You can make symbolic links: from /opt/local/lib to /usr/local/lib:
sudo ln -s /opt/local/lib/libvolk.dylib /usr/local/lib/libvolk.dylib
sudo ln -a /opt/local/lib/libliquid.dylib /usr/local/lib/libliquid.dylib

@rfc6919
Copy link

rfc6919 commented Dec 29, 2017

This issue is the result of macOS stripping environment variables that control dyld from the environment whenever a System Integrity Protection protected binary is executed (see the dyld(1) manpage). In this case, the problem is LD_LIBRARY_PATH and DYLD_LIBRARY_PATH being stripped when /usr/bin/env is executed through the luaradio shebang.

I'm not sure of a good general solution here, but the way I'm working around it is changing the luaradio shebang from #!/usr/bin/env luajit to #!/opt/brew/bin/luajit so my LD_LIBRARY_PATH=/opt/brew/lib isn't stripped out by the extra exec via env(1).

A simple reduction of this problem is:

XYZZY=foobar env | grep XYZZY => prints XYZZY=foobar
LD_LIBRARY_PATH=foobar env | grep LD_LIBRARY_PATH => prints nothing

or, assuming your libraries are in /opt/brew/lib, the actual ffi.load("liquid") failure:

LD_LIBRARY_PATH=/opt/brew/lib luajit -e 'require("ffi").load("liquid")' => succeeds
LD_LIBRARY_PATH=/opt/brew/lib env luajit -e 'require("ffi").load("liquid")' => error

@vsergeev
Copy link
Owner

Package added to MacPorts with macports/macports-ports#6539 with a wrapper script to fix dynamic library loading in LuaRadio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants