簡體   English   中英

LWJGL 原生操作系統 + JPMS + GRADLE

[英]LWJGL natives os + JPMS + GRADLE

錯誤: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.

我試圖將 java 平台模塊系統安裝/實現到我的一個項目中,而這個鏈接錯誤讓我着迷。 以下幾行是構建腳本和 module-info src 代碼。

模塊: 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()
}

應用模塊: 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 & 應用模塊:模塊信息.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;
}

> 我們如何通過使用 gradle 構建腳本並且不使用任何外部插件將這個原生操作系統鏈接到我們的項目?

我試過這個並且它正在工作,但不知何故我覺得這不是正確的方法?

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

並嘗試使用此應用程序擴展

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