How to fix Java 15 JNI "UnsatisfiedLinkError: A dynamic link library (DLL) initialization routine failed"

  c++, java, java-native-interface

I have found other posts of people having this exact error, but not one thus far has had a solution that worked for me. For reference, here are the things I have found:

JNI UnsatisfiedLinkError: A dynamic link library (DLL) initialization routine failed

Either their solution was not relevant to my particular scenario, or it did not fix the issue for me.

Everything is being compiled on the command line with a Windows 10 computer and using GCC (gcc-5.1.0-tdm64-1-c++) for compiling the C++ portions into a .dll, and JDK 15.0.1’s javac tool. There are three relevant files here, one being the header file derived from the java file.

public class Main {
    static {
        System.load("C:Users17659DocumentsProgrammingC++ & Java - JNI Testslibrary.dll");
    public static void main(String[] args) {
        new Main().outputText();
    private native void outputText();


/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Main */

#ifndef _Included_Main
#define _Included_Main
#ifdef __cplusplus
extern "C" {
 * Class:     Main
 * Method:    outputText
 * Signature: ()V
JNIEXPORT void JNICALL Java_Main_outputText
  (JNIEnv *, jobject);

#ifdef __cplusplus


#include <iostream>
#include "Main.h"

JNIEXPORT void JNICALL Java_Main_outputText(JNIEnv * a, jobject b)
    std::cout << "testing";

They are contained all within the folder with the absolute path of C:Users659DocumentsProgrammingC++ & Java - JNI Tests. With a command prompt set to that as the current directory, I run the following commands in order:

g++ -c -o Library.o -I"C:Users659Documentsjdk-15.0.1include" -I"C:Users659Documentsjdk-15.0.1includewin32" Library.cpp
g++ -shared -o library.dll Library.o
java Main

Despite the multiple things I have tried, I always get this same error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:Users659DocumentsProgrammingC++ & Java - JNI Testslibrary.dll: A dynamic link library (DLL) initialization routine failed
        at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
        at java.base/jdk.internal.loader.NativeLibraries$
        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(
        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(
        at java.base/java.lang.ClassLoader.loadLibrary(
        at java.base/java.lang.Runtime.load0(
        at java.base/java.lang.System.load(
        at Main.<clinit>(

I have used nm on the resulting .dll to make sure the name of the function is correct, and it does seem to be exactly as it should.

The entire point of this little project of mine is to figure out how JNI works, since I have a plan to write a small portion of a program in C++. The rest of the program though would work best in Java (for me). I do not know what I need to do to get this program to work, I have spent approximately 2 hours of googling and fiddling attempting to get it to function. This is on a 64-bit OS. How can I make this program run and print out the very little amount of text I would like it to print out?

Source: Windows Questions C++