Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

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

866026Jun 1 2011 — edited Nov 16 2011
Can any help help with a JNI question?

I"m sure the DLL is being found because if I set java.library.path to incorrect value I get this error instead: no HelloWorld in java.library.path

HelloWorld.java::
----------------------------------------------------
public class HelloWorld {
static void runTest() {
System.loadLibrary("HelloWorld");
helloWorld();
}
native public static void helloWorld();

public static void main(String[] args) {
HelloWorld.runTest();
}
}

HelloWorld.cpp
----------------------------------------------------
#include "HelloWorld.h"
#include <jni.h>
#include <iostream>

extern "C" JNIEXPORT void JNICALL Java_HelloWorld_helloWorld(JNIEnv *, jclass)
{
std::cout << "Java_HelloWorld_helloWorld" << std::endl;
}

I'm using VC express 2008
----------------------------------------------------

% c:\Progra~1\Java\jdk1.6.0_21\bin\javah -classpath ../bin HelloWorld
% cl /c /DWIN32 /GF /GR /EHa /EHc /TP /W2 /LD /MD HelloWorld.cpp
% cl /LD /MD HelloWorld.obj /FeHelloWorld.dll

Test output
----------------------------------------------------
% java -cp ../bin HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError: HelloWorld.dll: A dynamic link library (DLL) initialization routine failed
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at HelloWorld.runTest(HelloWorld.java:4)
at HelloWorld.main(HelloWorld.java:10)

Symbols in DLL.
----------------------------------------------------
% dumpbin /exports *.dll
Microsoft (R) COFF/PE Dumper Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.

Dump of file HelloWorld.dll

File Type: DLL

Section contains the following exports for HelloWorld.dll

00000000 characteristics
4DE6BD9D time date stamp Wed Jun 01 15:30:53 2011
0.00 version
1 ordinal base
1 number of functions
1 number of names

ordinal hint RVA name

1 0 00001000 _Java_HelloWorld_helloWorld@8

Removing the extern "C" has no effect. Symbol looks same according to dumpbin.

C++ Main to test DLL.
----------------------------------------------------

#include "HelloWorld.h"
#include <iostream>
#define WIN32_LEAN_AND_MEAN

using namespace std;

#include <windows.h>

typedef void JNICALL Java_HelloWorld_helloWorld_PROC(JNIEnv *, jclass);

int main(int ac, char *av[])
{
HMODULE inst = LoadLibrary("HelloWorld");

cout << "inst:" << inst << endl;
if ( inst == 0 ) return 0;
void * mth = GetProcAddress( inst, "_Java_HelloWorld_helloWorld@8");
cout << "mth:" << mth << endl;

if ( mth == 0 ) return 0;

Java_HelloWorld_helloWorld_PROC * proc = (Java_HelloWorld_helloWorld_PROC*)mth;

JNIEnv * envP = 0;
jclass clazz = 0;
(*proc)(envP,clazz);

FreeLibrary(inst);
}

Output is:
----------------------------------------------------
inst:10000000
mth:10001000
Java_HelloWorld_helloWorld


Thanks,

Comments

Timo Hahn
Answer

You can download the jdk doc from https://www.oracle.com/java/technologies/javase-jdk8-doc-downloads.html
Put the zip file somewhere local on your machine. Then open JDeveloper and select the menu tools->'manage libraries'. There you select the 'Java SE definition' tab and select the JDK version you are using
image.pngclick on the 'Doc Path' and select 'Add Entry' button. In the file dialog that opens, you go to the directory where you put the zip file and open it and select the 'docs/api' folder. Then save everything and restart JDev.
Then you'll get the javadoc you are missing.

Timo

Marked as Answer by ChristianM0147 · Jul 9 2021
ChristianM0147

Unfortunately it did not work. I did exactly what you described.
image.pngBut it seems that it has no effect.
image.pngDo you know what i may be missing?
Kind Regards

Timo Hahn

Well, you are looking at the code for the method and not the documentation. Select the 'Documentation' tab below the 'Element has no details' and you see the javadoc.
image.png
If you want to see the code you can download the jdk source and add the zip to the source path (in the manage libraries) where you added the path to the docs.

Timo

ChristianM0147

Oh... My bad. Thank you very much!

1 - 4
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 14 2011
Added on Jun 1 2011
3 comments
4,430 views