GDAL uses SWIG to generate its Java bindings, and there are two parts outputs from this: gdal.jar, and the native libgdalalljni.so that the JAR references. The ebuild installs gdal.jar but not the .so, and trying to run a Java project that uses GDAL results in: Native library load failed. java.lang.UnsatisfiedLinkError: no gdalalljni in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib] I think this is a simple oversight. These files exist in the work directory: # (cd /var/tmp/portage/sci-libs/gdal-3.0.4-r1 && ls -l $(find -iname '*gdalalljni*')) -rw-r--r-- 1 portage portage 1693 Nov 2 15:21 ./work/gdal-3.0.4/swig/java/libgdalalljni.la -rwxr-xr-x 1 portage portage 686328 Nov 2 15:21 ./work/gdal-3.0.4/swig/java/libgdalalljni.so lrwxrwxrwx 1 portage portage 19 Nov 2 15:21 ./work/gdal-3.0.4/swig/java/.libs/libgdalalljni.la -> ../libgdalalljni.la -rw-r--r-- 1 portage portage 1188 Nov 2 15:21 ./work/gdal-3.0.4/swig/java/.libs/libgdalalljni.lai lrwxrwxrwx 1 portage portage 23 Nov 2 15:21 ./work/gdal-3.0.4/swig/java/.libs/libgdalalljni.so -> libgdalalljni.so.26.0.4 lrwxrwxrwx 1 portage portage 23 Nov 2 15:21 ./work/gdal-3.0.4/swig/java/.libs/libgdalalljni.so.26 -> libgdalalljni.so.26.0.4 -rwxr-xr-x 1 portage portage 686328 Nov 2 15:21 ./work/gdal-3.0.4/swig/java/.libs/libgdalalljni.so.26.0.4 I can confirm that adding dolib.so "${S}"/swig/java/.libs/libgdalalljni.so{,.26,.26.0.4} into the "use java" conditional in src_install fixes the problem and lets Java load gdal.jar successfully. (The .../java/libgdalalljni.so file is just a copy of the .so in .libs, this can be seen in the build log.)
Created attachment 669809 [details] emerge --info
Also, a heads up that if GDAL is built with USE=-threads and used from Java, it issues this warning: WARNING: GDAL should be compiled with thread support for safe execution in Java. Rebuilding with USE=threads fixes it. I'm not sure if this warrants a REQUIRED_USE entry or if this should be left as a soft warning. There's an FAQ item relating to GDAL thread-safety: https://trac.osgeo.org/gdal/wiki/FAQMiscellaneous#IstheGDALlibrarythread-safe
Hello, Can I request that this change be applied please? This is still an issue with the current GDAL ebuild, and replacing: use java && java-pkg_dojar "${S}"/swig/java/gdal.jar with: if use java; then java-pkg_dojar "${S}"/swig/java/gdal.jar dolib.so "${S}"/swig/java/.libs/libgdalalljni.so{,.30,.30.*} fi or similar works for me. (Could interpolate the subslot too.) Also I think USE=java *should* force USE=threads via REQUIRED_USE. The docs for the Java library say: > Due to the fact the Java garbage collector works in a separate > thread from the main thread, it is necessary to configure GDAL with > multi-threading support, even if you do not use GDAL API from > several Java threads. - https://gdal.org/api/java/index.html
Sorry I didn't address this sooner. On it.
The bug has been closed via the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=230fd7226712fbbb901eb467a65339f21c6f50c5 commit 230fd7226712fbbb901eb467a65339f21c6f50c5 Author: Sam James <sam@gentoo.org> AuthorDate: 2022-03-14 12:07:45 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2022-03-14 12:07:45 +0000 sci-libs/gdal: add 3.4.2 Closes: https://bugs.gentoo.org/752399 Signed-off-by: Sam James <sam@gentoo.org> sci-libs/gdal/Manifest | 1 + sci-libs/gdal/gdal-3.4.2.ebuild | 327 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 328 insertions(+)
*** Bug 825506 has been marked as a duplicate of this bug. ***
Hello, and thanks very much for adding this in! I finally got around to testing it, and I'm ending up with errors loading the library at runtime, compared to my private ebuild: > Native library load failed. > java.lang.UnsatisfiedLinkError: no gdalalljni in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib] I think that (like with regular C shared libs) the unversioned 'libgdalalljni.so' link needs to be installed too, which 3.4.2-r1 doesn't do: > dolib.so "${S}"/swig/java/.libs/libgdalalljni.so.* If I point /usr/lib64/libgdalalljni.so to libgdalalljni.so.30 myself, my program works. Can we add this too please?
The bug has been closed via the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=d29631d70863c157bc34c1474cd63e8da5541b43 commit d29631d70863c157bc34c1474cd63e8da5541b43 Author: Sam James <sam@gentoo.org> AuthorDate: 2022-04-23 01:55:06 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2022-04-23 01:55:36 +0000 sci-libs/gdal: fix Java library installation Closes: https://bugs.gentoo.org/752399 Signed-off-by: Sam James <sam@gentoo.org> sci-libs/gdal/{gdal-3.4.2-r1.ebuild => gdal-3.4.2-r2.ebuild} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)