Bug 1316

Summary: Java 8 expects *.dylib instead of *.jnilib on OS X
Product: [JogAmp] General Reporter: Martin von Gagern <Martin.vGagern>
Component: buildsAssignee: Sven Gothel <sgothel>
Status: RESOLVED FIXED    
Severity: major CC: gouessej, sgothel
Priority: P2    
Version: 2.4.0   
Hardware: pc_x86_64   
OS: macosx   
Type: DEFECT SCM Refs:
gluegen 03bcef96e3105923ccc8c827b70b97ff0aa3464c joal 1cee337a9e888c9f223f36ffa05ceec5692bc08c jogl b83a912f19685e81b71c950914f0f82cc0e534bf jocl fb03bcb97326026155f17bbb4d8a634da6d62d43
Workaround: ---
Attachments: Gluegen patch
JOAL patch
JOCL patch
JOGL patch

Description Martin von Gagern 2016-07-14 12:20:17 CEST
For one application I've unpacked the native libs to a local directory (as part of the installation process), and I've set jogamp.gluegen.UseTempJarCache to false. This used to work in the past, but recently with Java 1.8 I see errors like this:

java.lang.UnsatisfiedLinkError: Can't load library: /…/libgluegen-rt.dylib

Searching the web for this, I found some indications that simply renaming the *.jnilib that came from the Jogamp release to *.dylib should work. I tried it out, and indeed it did work. So perhaps the natives jar file for OS X should be using those names? I haven't found any official documentation on that change so far.

I'm using JOGL 2.2.1 here, but I verified that in 2.3.2 the files are still called jnilib not dylib. (I'm confused that the version field here in Bugzilla doesn't allow me selecting a version earlier than 2.4.0 as the version where the bug was found, so I couldn't fill out that required field correctly.)

$ java -version
java version "1.8.0_72"
Java(TM) SE Runtime Environment (build 1.8.0_72-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.72-b15, mixed mode)

The OS is OS X 10.11.5 (15F34).

https://github.com/LWJGL/lwjgl/commit/a6bb6e31d888c07026ac0381c2900c895765ffbb was what suggested simply renaming the files. It's also the source naming java 1.8 as the release introducing this breakage, so I'm simply quoting that.
Comment 1 Julien Gouesse 2016-07-26 14:36:08 CEST
Would it still work with previous versions of Java under OS X, for example OpenJDK or Oracle Java 1.7?
Comment 2 Martin von Gagern 2016-07-26 17:27:50 CEST
Trying to track this down: In OpenJDK the file hotspot/src/os/bsd/vm/os_bsd.cpp has this:

#define JNI_LIB_PREFIX "lib"
#ifdef __APPLE__
#define JNI_LIB_SUFFIX ".dylib"
#else
#define JNI_LIB_SUFFIX ".so"
#endif

This should be the setting that is being used by the native implementation of System.mapLibraryName in jdk/src/share/native/java/lang/System.c. The file names .dylib since it got included into the repository in 2011. I don't know how the Apple resp. Oracle JDK gets derived from this, so I don't know for how long they supported both forms, if ever. I don't have a wide range of OpenJDK at my disposal just now to test this.

http://lists.apple.com/archives/java-dev/2012/Nov/msg00036.html reports dylib vs. jnilib naming issues with jogamp code as far back as 2012. JDK version unknown.
Comment 3 Julien Gouesse 2017-01-17 15:01:44 CET
Now I understand why .jnilib had been used:
http://markmail.org/message/cksb24oiwjszohvl#query:+page:1+mid:nvmhqaimybukzg4l+state:results

It seems reasonable to rename .jnilib files into .dylib, I'll do it as soon as possible.
Comment 4 Julien Gouesse 2019-03-29 19:30:59 CET
We should stop calling "rename.dylib" in make/build-jogl.xml, make/build-nativewindow.xml, make/build-newt.xml and make/build-oculusvr.xml. Then, we should replace "lib@{output.lib.name}.jnilib" by "lib@{output.lib.name}.dylib" in those files.
Comment 5 Sven Gothel 2019-03-29 19:39:27 CET
(In reply to Julien Gouesse from comment #4)
> We should stop calling "rename.dylib" in make/build-jogl.xml,
> make/build-nativewindow.xml, make/build-newt.xml and
> make/build-oculusvr.xml. Then, we should replace
> "lib@{output.lib.name}.jnilib" by "lib@{output.lib.name}.dylib" in those
> files.

Correct.
Comment 6 Julien Gouesse 2019-03-29 20:02:15 CET
(In reply to Sven Gothel from comment #5)
> (In reply to Julien Gouesse from comment #4)
> > We should stop calling "rename.dylib" in make/build-jogl.xml,
> > make/build-nativewindow.xml, make/build-newt.xml and
> > make/build-oculusvr.xml. Then, we should replace
> > "lib@{output.lib.name}.jnilib" by "lib@{output.lib.name}.dylib" in those
> > files.
> 
> Correct.

I've forgotten to stop calling "rename.dylib" in make/build.xml in GlueGen, JOAL and JOCL too.
Comment 7 Julien Gouesse 2019-03-29 20:37:03 CET
Created attachment 804 [details]
Gluegen patch
Comment 8 Julien Gouesse 2019-03-29 20:37:26 CET
Created attachment 805 [details]
JOAL patch
Comment 9 Julien Gouesse 2019-03-29 20:37:47 CET
Created attachment 806 [details]
JOCL patch
Comment 10 Julien Gouesse 2019-03-29 20:38:05 CET
Created attachment 807 [details]
JOGL patch
Comment 11 Julien Gouesse 2019-03-29 20:39:36 CET
(In reply to Sven Gothel from comment #5)
> (In reply to Julien Gouesse from comment #4)
> > We should stop calling "rename.dylib" in make/build-jogl.xml,
> > make/build-nativewindow.xml, make/build-newt.xml and
> > make/build-oculusvr.xml. Then, we should replace
> > "lib@{output.lib.name}.jnilib" by "lib@{output.lib.name}.dylib" in those
> > files.
> 
> Correct.

Please can you give a try to my patches? There is still a target whose name contains the word "rename" in GlueGen whereas it no longer move any file now, feel free to rename this target.
Comment 12 Sven Gothel 2019-03-30 01:31:46 CET
(In reply to Julien Gouesse from comment #11)
> (In reply to Sven Gothel from comment #5)
> > (In reply to Julien Gouesse from comment #4)
> > > We should stop calling "rename.dylib" in make/build-jogl.xml,
> > > make/build-nativewindow.xml, make/build-newt.xml and
> > > make/build-oculusvr.xml. Then, we should replace
> > > "lib@{output.lib.name}.jnilib" by "lib@{output.lib.name}.dylib" in those
> > > files.
> > 
> > Correct.
> 
> Please can you give a try to my patches? There is still a target whose name
> contains the word "rename" in GlueGen whereas it no longer move any file
> now, feel free to rename this target.

Julien, next time we both need to coordinate the work better ;-)
I did same changes and completed testing now.

BTW, I updated our poor test machine to latest OSX 10.14.13
and using XCode 10.2 - which was a necessary tedious exercise.
So OSX 10.11 is now the lowest baseline, since XCode 10.2 claims to be need OSX >= 10.11

Whatever, all tests passed.
Comment 13 Sven Gothel 2019-03-30 01:34:19 CET
Bug 1316: MacOSX: Keep *.dylib (Don't move to *.jnilib)
Since Java8 (or even earlier), JRE on OSX uses *.dylib native library suffix
instead of *.jnilib when automatically searching and loading them.

This is not easily being recognized by JogAmp, since we explicitly name
the native libraries with full path when testing with our TempJarCache.

Tested on OSX 10.14, XCode 10.2, SDK OSX 10.11 baseline min version
Java 1.8.0_192-b12
Working