java-native-access / java-native-access/jna

Loading of libs from subdirectories of the search path

Open
#551 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
8.9k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

Right now there is a problem to find libraries which are located in subdirectories of the search path.

In case you have a library with the path /usr/lib/bar/libfoo.so and the search path includes /usr/lib, then there is no way to load the library except the full path is given. This is not very nice if you consider that the lib could be in one of the following paths depending on the actual platform/distro used.
/usr/lib{32,x32,64}?
/usr/lib
/usr/lib/x86_64-linux-gnu
...

This is what needs to be done to load said lib:

NativeLibrary.addSearchPath("foo", "/usr/lib/bar");
Native.loadLibrary("foo", SomeClass.class);

or

Native.loadLibrary("/usr/lib/bar/libfoo.so", SomeClass.class);

However it would be nice to be able to write something like:

// name suffix which is appended to all search paths when the lib is loaded
Native.loadLibrary("bar", "foo", SomeClass.class);

or

// add suffix which is appended to all search paths when the lib is loaded
NativeLibrary.addSearchSuffixPath("foo", "bar");
Native.loadLibrary("foo", SomeClass.class);

or

// name the suffix together with the lib name
Native.loadLibrary("bar/foo", SomeClass.class);

I'm not entirely sure which would be the best solution, so it does not cause conflicts with the different platforms. However I prefer the 2nd option.

I can provide a patch if this feature is desired. What do you think?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Native.loadLibrary and NativeLibrary.addSearchPath entry points, then trace how search paths are resolved across platforms. Compare the proposed APIs and define one cross-platform behavior; done means a library such as /usr/lib/bar/libfoo.so can be loaded by name when /usr/lib is configured as the search path.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.