ERROR: 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. The following lines are build script and the module-info src code.
lib module: 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
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
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?
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) }
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.