I'm using org.openpnp:opencv:4.7.0-0
in a Java maven project (Java version 17.0.6+10-LTS) and I'm loading the library as recommended for Java > 12 via OpenCV.loadLocally();
. The project builds and runs perfectly on my M2 Mac.
On our DEV server that is an Ubuntu 22.04 x86-64 VM (with full JDK Java 17.0.6+10-Ubuntu-0ubuntu122.04), when I either run the jar built on my Mac or do a full build from sources on that machine, the jar produces the same error, when this code is executed:
java.lang.AssertionError: java.lang.UnsatisfiedLinkError:
/tmp/opencv_openpnp12784852236417917500/nu/pattern/opencv/linux/x86_64/libopencv_java470.so: failed to map segment from shared object
Am I missing some step to run this on x86 Linux or is it just a bug in OpenPnP's OpenCV fork?
PS I've raised an issue in their issue tracker but responses there are slow or non-existent.
The error message failed to map segment from shared object often indicates an issue with memory mapping of shared libraries in Linux.
One of the likely causes of this issue could be that the file system which /tmp directory is located on is mounted with noexec (which means it doesn't allow execution of binaries) or possibly nosuid or nodev option. Some environments have this as a security measure. In such case, the JVM may not be able to execute the native libraries extracted from the JAR to the /tmp directory.
You can verify if the /tmp directory is mounted with noexec by running the command mount in your Ubuntu VM and inspecting its output. If it's indeed the case, there are a couple of solutions:
Remount the /tmp directory without the noexec option: This is performed using the command:
sudo mount -o remount,exec /tmp
Note that it could decrease the security of your system.