dlopen() and (non-support in) MacPorts

Joshua Root jmr at macports.org
Mon Mar 19 02:00:32 UTC 2018


On 2018-3-19 10:55 , Mojca Miklavec wrote:
> Hi,
> 
> I'm maintaining the dvisvgm port which links against libgs and works
> with ghostscript as expected.
> 
> But I also compile that binary as a standalone one, as part of TeX
> Live (maybe MacTeX rings a bell, even though I'm not the one providing
> MacTeX itself). That binary uses dlopen() to find libgs on the fly (if
> one exists, else it just lacks certain functionality).
> 
> I just received a request from some user who is annoyed by the fact
> that he always has to use
>     dvisvgm --libgs="/opt/local/lib/libgs.9.22.dylib"
> (which tries to open libgs from the specified location) and I would
> like to find a better long-term solution for that problem.
> 
> Here's the relevant documentation:
> 
> https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/dlopen.3.html
> 
> Setting
>     export LD_LIBRARY_PATH="/opt/local/lib"
> in .bash_profile works, but I'm not really happy with suggesting that
> solution long term.
> 
> HB developers initially submitted a patch
>     https://github.com/mgieseki/dvisvgm/issues/66
> which makes sure that this standalone binary automatically finds
> ghoscript from HB which works because /usr/local/lib is automatically
> checked by macOS during dlopen(), but /opt/local/lib is not.
> 
> I'm not sure what I could do (in upstream) to provide a better
> experience to users with ghoscripts from MacPorts and the standalone
> binary from outside of MacPorts.
> 
> It would help if at least the /opt/local prefix was checked for
> existence of the library. If the library was linked in the usual way,
> I could probably use the rpath trick, but I assume this doesn't work
> for dlopen().

Keeping in mind all the reasons why just using whatever libraries you
happen to find wherever is a bad idea...

You can give dlopen() a full path. You can try it with different full
paths if it fails. You can also adjust LD_LIBRARY_PATH in your app to
make dlopen() search whatever directories you like in whatever order you
like.

- Josh


More information about the macports-dev mailing list