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

try to load library from /usr/lib/jni if property jna.boot.library.path is not set #1499

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/com/sun/jna/Native.java
Expand Up @@ -952,6 +952,9 @@ private static void loadNativeDispatchLibrary() {

String libName = System.getProperty("jna.boot.library.name", "jnidispatch");
String bootPath = System.getProperty("jna.boot.library.path");
if (bootPath == null) {
bootPath = "/usr/lib/jni" + File.pathSeparator + "/usr/lib/" + Platform.getMultiArchPath() + "/jni";
}
niol marked this conversation as resolved.
Show resolved Hide resolved
if (bootPath != null) {
// String.split not available in 1.4
StringTokenizer dirs = new StringTokenizer(bootPath, File.pathSeparator);
Expand Down
26 changes: 1 addition & 25 deletions src/com/sun/jna/NativeLibrary.java
Expand Up @@ -944,7 +944,7 @@ static double parseVersion(String ver) {
// so for platforms which are not multi-arch
// this should continue to work.
if (Platform.isLinux() || Platform.iskFreeBSD() || Platform.isGNU()) {
String multiArchPath = getMultiArchPath();
String multiArchPath = Platform.getMultiArchPath();

// Assemble path with all possible options
paths = new String[] {
Expand Down Expand Up @@ -990,30 +990,6 @@ static double parseVersion(String ver) {
librarySearchPath.addAll(initPaths("jna.platform.library.path"));
}

private static String getMultiArchPath() {
String cpu = Platform.ARCH;
String kernel = Platform.iskFreeBSD()
? "-kfreebsd"
: (Platform.isGNU() ? "" : "-linux");
String libc = "-gnu";

if (Platform.isIntel()) {
cpu = (Platform.is64Bit() ? "x86_64" : "i386");
}
else if (Platform.isPPC()) {
cpu = (Platform.is64Bit() ? "powerpc64" : "powerpc");
}
else if (Platform.isARM()) {
cpu = "arm";
libc = "-gnueabi";
}
else if (Platform.ARCH.equals("mips64el")) {
libc = "-gnuabi64";
}

return cpu + kernel + libc;
}

/**
* Get the library paths from ldconfig cache. Tested against ldconfig 2.13.
*/
Expand Down
34 changes: 32 additions & 2 deletions src/com/sun/jna/Platform.java
Expand Up @@ -262,8 +262,12 @@ else if ("zarch_64".equals(arch)) {
arch = "ppc64le";
}
// Map arm to armel if the binary is running as softfloat build
if("arm".equals(arch) && platform == Platform.LINUX && isSoftFloat()) {
arch = "armel";
if("arm".equals(arch) && platform == Platform.LINUX ) {
if(isSoftFloat()) {
arch = "armel";
} else if(!is64Bit()) {
arch = "armhf";
}
niol marked this conversation as resolved.
Show resolved Hide resolved
}

return arch;
Expand Down Expand Up @@ -352,4 +356,30 @@ static String getNativeLibraryResourcePrefix(int osType, String arch, String nam
}
return osPrefix;
}

public static String getMultiArchPath() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why this was moved into public visibility. I can see why people might want this, but this is not a fix, but a feature.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite handy to have this available.

String cpu = ARCH;
String kernel = iskFreeBSD()
? "-kfreebsd"
: (isGNU() ? "" : "-linux");
String libc = "-gnu";

if (isIntel()) {
cpu = (is64Bit() ? "x86_64" : "i386");
}
else if (isPPC()) {
cpu = cpu.replace("ppc", "powerpc");
}
else if (isARM()) {
cpu = (is64Bit() ? "aarch64" : "arm");
libc = is64Bit()
? "-gnu"
: ("armhf".equals(ARCH) ? "-gnueabihf" : "-gnueabi");
}
else if (ARCH.equals("mips64el")) {
libc = "-gnuabi64";
}

return cpu + kernel + libc;
}
}