imgui-java + Java = UnsatisfiedLinkError(libglfw.so)

Viewed 148

I am catching an error when I try to compile the template application from imgui-java library using gradle.

Main.java

import imgui.ImGui;
import imgui.app.Application;

public class Main extends Application {
    @Override
    protected void configure(Configuration config) {
        config.setTitle("Dear ImGui is Awesome!");
    }

    @Override
    public void process() {
        ImGui.text("Hello, World!");
    }

    public static void main(String[] args) {
        launch(new Main());
    }
}

Error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to dynamically load library: /tmp/lwjglbuwnertys/3.2.3-SNAPSHOT/libglfw.so(error = null)
        at org.lwjgl.system.linux.LinuxLibrary.loadLibrary(LinuxLibrary.java:32)
        at org.lwjgl.system.linux.LinuxLibrary.<init>(LinuxLibrary.java:19)
        at org.lwjgl.system.APIUtil.apiCreateLibrary(APIUtil.java:123)
        at org.lwjgl.system.Library.loadNative(Library.java:360)
        at org.lwjgl.system.Library.loadNativeFromLibraryPath(Library.java:349)
        at org.lwjgl.system.Library.loadNative(Library.java:264)
        at org.lwjgl.system.Library.loadNative(Library.java:222)
        at org.lwjgl.glfw.GLFW.<clinit>(GLFW.java:674)
        at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
        at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1042)
        at java.base/jdk.internal.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
        at java.base/jdk.internal.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:186)
        at java.base/java.lang.reflect.Field.acquireFieldAccessor(Field.java:1105)
        at java.base/java.lang.reflect.Field.getFieldAccessor(Field.java:1086)
        at java.base/java.lang.reflect.Field.getInt(Field.java:594)
        at org.lwjgl.system.APIUtil.apiClassTokens(APIUtil.java:348)
        at org.lwjgl.glfw.GLFWErrorCallback$1.<init>(GLFWErrorCallback.java:98)
        at org.lwjgl.glfw.GLFWErrorCallback.createPrint(GLFWErrorCallback.java:97)
        at imgui.app.Window.initWindow(Window.java:70)
        at imgui.app.Window.init(Window.java:48)
        at imgui.app.Application.initialize(Application.java:91)
        at imgui.app.Application.launch(Application.java:81)
        at Main.main(Main.java:54)

build.gradle:

plugins {
    id 'application'                                                                                                                                                   
}

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'junit:junit:4.13.1'

    implementation 'com.google.guava:guava:30.0-jre'

    String imgui_java_version = '1.84.1.0'    
    implementation "io.github.spair:imgui-java-app:$imgui_java_version"
}

application {
    mainClass = 'Main'
}

Creater of this library say:

So you only need one dependency line or one jar in classpath to make everything to work. You don't need to add separate dependencies to LWJGL or native libraries, since they are already included.

So I can't understand, why do I have a problem? How can I fix it?

1 Answers

It may depend on the version of imgui-java you're using, on how you actually installed it, maybe on your OS...

My advice: have a look at the project issues. Many users seem to have had similar UnsatisfiedLinkError issues.

In case you're not familiar with Java: UnsatisfiedLinkError is the error you get when Java is trying to load some native library to interact with.

In your case, the missing library is /tmp/lwjglbuwnertys/3.2.3-SNAPSHOT/libglfw.so.

Maybe you could check if it is present at this location? Maybe it is present with another name (something like libimgui-java64.so instead)? If it is the case, try to rename the library.

Related