This discussion is archived
3 Replies Latest reply: Nov 29, 2011 3:37 PM by jschellSomeoneStoleMyAlias RSS

UnsatisfiedLinkError:  A dynamic link library (DLL) initialization routine

MichaelT Newbie
Currently Being Moderated
I get this error only when building a native library with /MD on Win64.

Envrionment
Windows Server 2008 R2 (64 bit)

JDK1.6 (32 bit)
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode)

MS Visual Studio 2008
Microsoft (R) 32-bit C/C+ Optimizing Compiler Version 15.00.30729.01 for 80x86+

If I compile with "cl /O1 /EHsc /LD /IC:\Apps\Dvlp\jdk1.6.0\include /IC:\Apps\Dvlp\jdk1.6.0\include\win32 ..." then System.loadLibrary(...) succeeds.

If I compile with "cl */MD* /O1 /EHsc /LD /IC:\Apps\Dvlp\jdk1.6.0\include /IC:\Apps\Dvlp\jdk1.6.0\include\win32 ..." then System.loadLibrary(...) fails with "A dynamic link library (DLL) initialization routine failed."

After reading Microsoft's description of the /MD linker option I'm assuming this is a bitness issue but with my limited experience on Windows I'm afraid I'm stuck. Note, I must build with /MD, it's a requirement. Any suggestions on what to do next?

Edited by: user709182 on Nov 16, 2011 2:55 PM
  • 1. Re: UnsatisfiedLinkError:  A dynamic link library (DLL) initialization routine
    EJP Guru
    Currently Being Moderated
    I get this error only when building a native library with /MD on Win64.
    Don't you mean when executing on Win64?

    I was never able to get JNI working with /MD even on 32-bit systems, and that was at a time when I had considerable expertise in /MD and building DLLs generally.

    If you design your interface to your other C code carefully you don't need to use /MD for the JNI DLL.
  • 2. Re: UnsatisfiedLinkError:  A dynamic link library (DLL) initialization routine
    MichaelT Newbie
    Currently Being Moderated
    This appears to be a general problem with building a 32 bit app with /MD then executing in a 64 bit windows environment. At run time load library finds a 64 bit version of the c runtime hence the 32 bit library fails to load. Fortunately we are moving to 64 bit builds of our app so I am now generating 64 bit builds myself. I have no problems with /MD when all is 64 bit. By the way, building with /MD is requirement imposed by 3rd party libraries I depend upon so removing it is not an option.
  • 3. Re: UnsatisfiedLinkError:  A dynamic link library (DLL) initialization routine
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    MichaelT wrote:
    By the way, building with /MD is requirement imposed by 3rd party libraries I depend upon so removing it is not an option.
    An alternative still exists. Do not use JNI. Instead
    1. Wrap the target native code in an executable.
    2. Add a communication api.
    3. Test and debug as the executable.
    4. Run the executable via Runtime.exec/ProcessBuilder
    5. Execute the functionality via the communication api.

    No JNI in the above. Also no possibility that the native code can crash your VM. Even if the exe crashes you can add restart code to deal with it.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points