简体   繁体   English

LWJGL 原生操作系统 + JPMS + GRADLE

[英]LWJGL natives os + JPMS + GRADLE

ERROR: UnsatisfiedLinkError错误:UnsatisfiedLinkError

[LWJGL] Failed to load a library. Possible solutions:
    a) Add the directory that contains the shared library to -Djava.library.path or -Dorg.lwjgl.librarypath.
    b) Add the JAR that contains the shared library to the classpath.
[LWJGL] Enable debug mode with -Dorg.lwjgl.util.Debug=true for better diagnostics.
[LWJGL] Enable the SharedLibraryLoader debug mode with -Dorg.lwjgl.util.DebugLoader=true for better diagnostics.
Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to locate library: lwjgl.dll
    at org.lwjgl/org.lwjgl.system.Library.loadSystem(Library.java:162)
    at org.lwjgl/org.lwjgl.system.Library.loadSystem(Library.java:62)
    at org.lwjgl/org.lwjgl.system.Library.<clinit>(Library.java:50)
    at org.lwjgl.glfw/org.lwjgl.glfw.GLFW.<clinit>(GLFW.java:674)
FAILURE: Build failed with an exception.

I tried to had/implement the java platform module system to one of my projects and this linking error had me.我试图将 java 平台模块系统安装/实现到我的一个项目中,而这个链接错误让我着迷。 The following lines are build script and the module-info src code.以下几行是构建脚本和 module-info src 代码。

lib module: buld.gradle .kts模块: buld.gradle .kts

import org.gradle.kotlin.dsl.support.unzipTo

plugins {
    `java-library`
}
group = "com.moc"
version = "0.0"
java {
    modularity.inferModulePath.set(true)
}
repositories {
    mavenCentral()
}
val nativesClasses: Configuration by configurations.creating {
    isTransitive = false
    extendsFrom(configurations.runtimeOnly.get())
}
tasks.register("unzips") {
    nativesClasses.asFileTree.forEach {
        unzipTo(File("${buildDir}/libs/natives"), it)
    }
}
dependencies {
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.1")

    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
    
    implementation(fileTree("hard-typed/path/for/the/lwjgl-3.2.3/lwjgl.jar") )
    implementation(fileTree("hard-typed/path/for/the/lwjgl-3.2.3/lwjgl-glfw.jar") )
    implementation(fileTree("hard-typed/path/for/the/lwjgl-3.2.3/lwjgl-assimp.jar") )
    implementation(fileTree("hard-typed/path/for/the/lwjgl-3.2.3/lwjgl-opengl.jar") )

    runtimeOnly( fileTree("hard-typed/path/for/the/lwjgl-3.2.3/lwjgl-natives-windows.jar" ) )
    runtimeOnly( fileTree("hard-typed/path/for/the/lwjgl-3.2.3/wjgl-glfw-natives-windows.jar" ) )
    runtimeOnly( fileTree("hard-typed/path/for/the/lwjgl-3.2.3/lwjgl-assimp-natives-windows.jar" ) )
    runtimeOnly( fileTree("hard-typed/path/for/the/lwjgl-3.2.3/lwjgl-opengl-natives-windows.jar" ) )
}
tasks.test {
    useJUnitPlatform()
}

app module: build.gradle .kts应用模块: build.gradle .kts

plugins {
    application
}
group = "com.moc"
version = "0.0"
java {
    modularity.inferModulePath.set(true)
}
application {
    mainModule.set("moc.app")
    mainClass.set("com.moc.main.App")
}
tasks.withType<JavaExec> {
    System.setProperty("org.lwjgl.librarypath",
        "hard-typed/path/of/natives-os/lwjgl;" +
                "hard-typed/path/of/natives-os/opengl;" +
                "hard-typed/path/of/natives-os/glfw;" +
                "hard-typed/path/of/natives-os/assimp" )
}
repositories {
    mavenCentral()
}
dependencies {
    implementation(project(":lib"))
}

lib & app module: module-info .java lib & 应用模块:模块信息.java

module moc.lib {
    requires org.lwjgl.glfw;
    requires org.lwjgl.opengl;
    requires org.lwjgl.assimp;
    exports com.moc;
}
module moc.app {
    requires moc.lib;
}

> How do we link this natives os to our project by using a gradle build script and without any external plugins? > 我们如何通过使用 gradle 构建脚本并且不使用任何外部插件将这个原生操作系统链接到我们的项目?

I tried this one and it's working but somehow I feel this is not the right way?我试过这个并且它正在工作,但不知何故我觉得这不是正确的方法?

tasks.withType<JavaExec> {
    val lwjgl = System.setProperty("org.lwjgl.librarypath", "../libs/natives"
    systemProperty("org.lwjgl.librarypath", System.getProperty("org.lwjgl.librarypath") )
}
repositories {
    mavenCentral()
}

And try this one for the application extension并尝试使用此应用程序扩展

val lwjgNativesProp : String? = System.setProperty("org.lwjgl.librarypathz", "../libs/natives")

application {
    applicationDefaultJvmArgs = arrayListOf("-Dorg.lwjgl.librarypath=${System.getProperty("org.lwjgl.librarypathz")}")
}

tasks.withType<JavaExec> {
    lwjglNativesProp?.let { systemProperty("org.lwjgl.librarypath", it) }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM