为什么我收到错误“java.lang.UnsatisfiedLinkError:无法加载库”什么时候可以找到该文件?

发布于 2025-01-18 23:58:12 字数 2402 浏览 0 评论 0原文

尽管文件明显存在并且可以读取,为什么我会收到此错误?

错误

我的项目正在使用 lwjgl 和 imgui-java。我已将 -Dimgui.library.path="libs" (存储有问题的 .dylib 的位置)添加到我的 VM 选项中,并且应用程序应该打开,显示演示 IMGUI。

我还在下面发布了我的 build.gradle 文件:

plugins {
    id 'java'
}

group 'org.tpsgames'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}

import org.gradle.internal.os.OperatingSystem

project.ext.lwjglVersion = "3.3.1"
project.ext.jomlVersion = "1.10.4"
project.ext.imguiVersion = '1.86.4'
project.ext.lwjglNatives = "natives-macos"

switch (OperatingSystem.current()) {
    case OperatingSystem.MAC_OS:
        project.ext.lwjglNatives = System.getProperty("os.arch").startsWith("aarch64") ? "natives-macos-arm64" : "natives-macos"
        break
}

repositories {
    mavenCentral()
}

dependencies {
    implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
    implementation "io.github.spair:imgui-java-app:1.86.4"
    implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
    implementation fileTree('libs') {include '*.jar'}
    ['', '-opengl', '-glfw'].each {
        implementation "org.lwjgl:lwjgl$it:$lwjglVersion"
        implementation "org.lwjgl:lwjgl$it::natives-macos"
    }
    implementation "io.github.spair:imgui-java-binding:1.86.4"
    implementation "io.github.spair:imgui-java-lwjgl3:1.86.4"
    implementation "io.github.spair:imgui-java-natives-macos:1.86.4"
    implementation "org.lwjgl:lwjgl"
    implementation "org.lwjgl:lwjgl-assimp"
    implementation "org.lwjgl:lwjgl-glfw"
    implementation "org.lwjgl:lwjgl-nfd"
    implementation "org.lwjgl:lwjgl-openal"
    implementation "org.lwjgl:lwjgl-opengl"
    implementation "org.lwjgl:lwjgl-stb"
    runtimeOnly "org.lwjgl:lwjgl::$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-assimp::$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-glfw::$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-nfd::$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-openal::$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-opengl::$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-stb::$lwjglNatives"
    implementation "org.joml:joml:1.10.4"
}

test {
    useJUnitPlatform()
}

Why am I receiving this error even though the file is clearly there and it could be read?

The Error

My project is using lwjgl and imgui-java. I have added -Dimgui.library.path="libs" (where the .dylib in question is stored) to my VM options and the application should open, displaying the demo IMGUI.

I have also posted my build.gradle file below:

plugins {
    id 'java'
}

group 'org.tpsgames'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}

import org.gradle.internal.os.OperatingSystem

project.ext.lwjglVersion = "3.3.1"
project.ext.jomlVersion = "1.10.4"
project.ext.imguiVersion = '1.86.4'
project.ext.lwjglNatives = "natives-macos"

switch (OperatingSystem.current()) {
    case OperatingSystem.MAC_OS:
        project.ext.lwjglNatives = System.getProperty("os.arch").startsWith("aarch64") ? "natives-macos-arm64" : "natives-macos"
        break
}

repositories {
    mavenCentral()
}

dependencies {
    implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
    implementation "io.github.spair:imgui-java-app:1.86.4"
    implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
    implementation fileTree('libs') {include '*.jar'}
    ['', '-opengl', '-glfw'].each {
        implementation "org.lwjgl:lwjgl$it:$lwjglVersion"
        implementation "org.lwjgl:lwjgl$it::natives-macos"
    }
    implementation "io.github.spair:imgui-java-binding:1.86.4"
    implementation "io.github.spair:imgui-java-lwjgl3:1.86.4"
    implementation "io.github.spair:imgui-java-natives-macos:1.86.4"
    implementation "org.lwjgl:lwjgl"
    implementation "org.lwjgl:lwjgl-assimp"
    implementation "org.lwjgl:lwjgl-glfw"
    implementation "org.lwjgl:lwjgl-nfd"
    implementation "org.lwjgl:lwjgl-openal"
    implementation "org.lwjgl:lwjgl-opengl"
    implementation "org.lwjgl:lwjgl-stb"
    runtimeOnly "org.lwjgl:lwjgl::$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-assimp::$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-glfw::$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-nfd::$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-openal::$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-opengl::$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-stb::$lwjglNatives"
    implementation "org.joml:joml:1.10.4"
}

test {
    useJUnitPlatform()
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷鸟归林 2025-01-25 23:58:12

您的计算机很可能具有带有ARM架构的CPU,例如M1芯片,而不是X86架构。

因此,JVM进程无法加载IMGUI-JAVA64.DYLIB共享库,因为Imgui-Java当前仅船舶X86 CPU架构共享库,而不是ARM的库。

请参阅此GitHub问题: https://github.com/spair/spair/imgui-java/issues/ 123
此(当前打开)github拉请求: https://github.com/spair/spair/spair/imgui -java/pult/112 为IMGUI-JAVA添加ARM CPU支持。

您唯一的解决方案是可能将当前已完成的工作纳入该GitHub拉的请求中,并在本地为您的ARM CPU编译IMGUI-JAVA,或等到PR合并到合并PR并与MacOS Arm共享库的IMGui-Java船舶释放。

Your computer very likely has a CPU with the ARM architecture, such as the M1 chip, instead of the x86 architecture.

Therefore, the JVM process cannot load the imgui-java64.dylib shared library because imgui-java currently only ships x86 CPU architecture shared libraries, not ARM ones.

See this GitHub issue: https://github.com/SpaiR/imgui-java/issues/123
and this (currently open) GitHub Pull Request: https://github.com/SpaiR/imgui-java/pull/112 to add ARM CPU support for imgui-java.

Your only solution is to probably incorporate the work currently having been done in that GitHub Pull Request and compile imgui-java locally yourself for your ARM CPU or wait until the PR is merged and a release of imgui-java ships with macOS ARM shared libraries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文