Skip to content

LibraryLoader.search() path not taken into consideration unless also in LD_LIBRARY_PATH #303

@ja2142

Description

@ja2142

On linux, when loading library outside of normal library paths, the LD_LIBRARY_PATH has to be set - if it isn't, library fails to load.

Example:

Let's say there's a lib at ~/mylib/libmylib.so. Trying to load it with:

MyLib lib = LibraryLoader.create(MyLib.class).failImmediately()
    .search("~/mylib")
    .load("libmylib.so");

Fails with java.lang.UnsatisfiedLinkError: libmylib.so: cannot open shared object file: No such file or directory.

When the path in which library resides is added to LD_LIBRARY_PATH (by export LD_LIBRARY_PATH=~/mylib), code above loads the library without any problems.

Expected behaviour:

I'd expect LibraryLoader.search(path) to work, without me having to deal with environment variables. Maybe a fix would be as easy as just prepending path from LibraryLoader.search() to LD_LIBRARY_PATH?

Why:

I'm trying to get a project with native libs packaged in a .jar to work. It works by unpacking these native libs into some directory in users home, and then loading them with jnr-ffi. Again I'd hope that LibraryLoader.search(path).load(lib) would just work, without having to fiddle with env variables.

May be related to #129 (paths added via search() seem to have priority, as long as they are in LD_LIBRARY_PATH - otherwise they don't seem to be taken into consideration at all)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions