LWJGL Forum

Programming => Bug Reports / RFE => Topic started by: Source_of_Truth on January 03, 2021, 18:09:19

Title: [SOLVED] Native-DLL Issues in Java15 (or is it my IDE)?
Post by: Source_of_Truth on January 03, 2021, 18:09:19
Hi  :) I have been working on my LWJGL project for some time now. I have been updating my IDE, IntelliJ in this case, and afterwards, my project has issues to find certain native DLLs.

The lib really came a long way (I first encountered it in its early 2.0 days) and plenty of nice convient tools exist now, like the Maven-POM Generator on the website. Since I am using XML-code generated (partially, I admit) by said tool, I think the POM-stuff is in order and it did work fine beforehand. Compilation still works but running the code generates these errors:
[LWJGL] Failed to load a library
Well, obviously this happens only at runtime, the bane of the native code. In this case, it is having an issue with lwjgl_stb.dll but I think this is just because it hits that part of the code first. I debugged a bit and figured out that, to my surprise, the native-DLLs are taken from a temporary folder, in this case it was C:\Users\[MYUSR]~1\AppData\Local\Temp\lwjgl[MYUSR]\3.2.3-build-13. That directory contained:
* lwjgl_opengl.dll
* lwjgl.dll
* glfw.dll

which is certainly not enough, I would have expected a few more DLLs, given my code, including the STB-ones. I must admit that I was a bit confused about this temp-business, what exactly is going on there? I would have expected some JARs in my target folder, instead there is a temporary one while the only JAR in the target-folder is the lwjglx-debug-1.0.0.jar-one, probably due to my debugging.

A call with
mvn help:active-profiles
tells me that lwjgl-natives-windows-amd64 is active, which seems okay to me.

Is there some known incompatibility with Java 15, the IntelliJ IDEA or newer Maven versions?

Thanks in advance. Happy new year  ;)

EDIT: every time I try to attach the POM, the ngix of the forum gives me a 500  >:(
Title: Re: Native-DLL Issues in Java15 (or is it my IDE)?
Post by: KaiHH on January 03, 2021, 18:14:50
Quote from: Source_of_Truth on January 03, 2021, 18:09:19
I was a bit confused about this temp-business, what exactly is going on there? I would have expected some JARs in my target folder, instead there is a temporary one while the only JAR in the target-folder is the lwjglx-debug-1.0.0.jar-one, probably due to my debugging.
All OSes (like Windows, Linux and Mac OS) can only load native libraries when those are backed by a file in a filesystem. Therefore, when you rely on the SharedLibraryLoader in LWJGL3 to load the natives off the jar files (those with "-natives-" in their names) then LWJGL 3 will use its SharedLibraryLoader to first extract the natives from the classpath into said temporary folder in your user's temporary directory, and then instruct the OS to load the native shared libraries from there.

How does the dependencies section of your pom.xml look like, exactly? Do you use the classpath or the modulepath with the Java 9+ Platform Module System?
Title: Re: Native-DLL Issues in Java15 (or is it my IDE)?
Post by: Source_of_Truth on January 03, 2021, 18:33:00
Quote from: KaiHH on January 03, 2021, 18:14:50
All OSes (like Windows, Linux and Mac OS) can only load native libraries when those are backed by a file in a filesystem. Therefore, when you rely on the SharedLibraryLoader in LWJGL3 to load the natives off the jar files (those with "-natives-" in their names) then LWJGL 3 will use its SharedLibraryLoader to first extract the natives from the classpath into said temporary folder in your user's temporary directory, and then instruct the OS to load the native shared libraries from there.
I see. That will fun when deploying the application ;D but that is a question for a later time.

Quote from: KaiHH on January 03, 2021, 18:14:50
How does the dependencies section of your pom.xml look like, exactly? Do you use the classpath or the modulepath with the Java 9+ Platform Module System?

Like I said, the forum dies on me. Well, here is a shortened version:


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>MYPROJECT</groupId>
    <artifactId>MYARTIFACT</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
<lwjgl.version>3.2.3</lwjgl.version>
        <java.languagelevel>15</java.languagelevel>
        <mvn.compilerplugin>3.8.1</mvn.compilerplugin>
        <mvn.assemblyplugin>3.1.1</mvn.assemblyplugin>
        <mvn.surefireplugin>3.0.0-M5</mvn.surefireplugin>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <build>
      (...)
    </build>

    <profiles>
    <!-- all LWJGL profiles -->
<profile>
<id>lwjgl-natives-windows-amd64</id>
<activation>
<os>
<family>windows</family>
<arch>amd64</arch>
</os>
</activation>
<properties>
<lwjgl.natives>natives-windows</lwjgl.natives>
</properties>
</profile>
</profiles>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-bom</artifactId>
<version>${lwjgl.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!--there is obviously stuff missing here, shortened for clarification-->
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-stb</artifactId>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-stb</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
</dependencies>

</project>


I think that is the classical approach, yes?
Title: Re: Native-DLL Issues in Java15 (or is it my IDE)?
Post by: KaiHH on January 03, 2021, 18:59:33
The pom looks fine. What does:

System.getProperty("java.class.path")

equal at runtime (e.g. when you print or debug/inspect it)?
Does it contain the actual natives jars?

As for deployment: When you ship a final product, you are expected to ship the natives yourself and point either `java.library.path` or `lwjgl.library.path` to the folder.
Title: Re: Native-DLL Issues in Java15 (or is it my IDE)?
Post by: Source_of_Truth on January 03, 2021, 19:16:18
Uh, this is not good. The new IDE version seems to default to C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3\lib\idea_rt.jar  :(
Title: Re: Native-DLL Issues in Java15 (or is it my IDE)?
Post by: KaiHH on January 03, 2021, 19:31:41
You could simply re-import the Maven project. I don't have any problems with IntelliJ IDEA 2020.3.1 or with any other previous IntelliJ or Eclipse version with LWJGL projects using the Maven.
Do you have a module-info.java file in your source path?
Title: Re: Native-DLL Issues in Java15 (or is it my IDE)?
Post by: Source_of_Truth on January 04, 2021, 13:35:06
I have checked my module-info file and indeed, the requires-declarations for some of the natives where not present. Adding them fixed it.

What I utterly fail to understand is how this could have been working for the last half year without these statements, where the hell did it load the stb and lz4-natives from beforehand?

Anyway, solved. Thanks  :)