PRB: Getting "Unsatisfied Link Error" When Using J/Direct

Last reviewed: February 10, 1998
Article ID: Q180713
The information in this article applies to:
  • SDK for Java, versions 2.0, 2.01
  • Microsoft Win32 Virtual Machine for Java
  • Microsoft Visual J++, versions 1.0, 1.1

SYMPTOMS

The following error message is generated when trying to run a Java application or applet that uses J/Direct:

   Error: Java.lang.unsatisified link error...

CAUSE

This error can occur if an old version of the Java compiler (Jvc.exe) is used. Make sure you are using Jvc.exe version 4337 or later. Version 4337 is shipped with the Microsoft SDK 2.0 for Java. Since J/Direct requires the use of compile-time directives like @dll.import (to import native methods from a DLL) it requires the latest version of Jvc.exe, which can recognize these compile-time directives.

NOTE: Virtual Machine for Java build 2252 (or higher) is required for J/Direct.

RESOLUTION

After you have installed the SDK 2.0 or 2.01 for Java, if you are trying to build your Java applet or application that uses J/Direct from within the Developer Studio, then add the SDK-Java.20\Bin directory to the Visual J++ executable files path as follows:

  1. From the Tools menu, point to Options and click the Directories tab.

  2. Under the Platform menu, make sure "Java Virtual Machine" is selected.

  3. Under "Show directories for," choose "Executable files."

  4. Include the directory "C:\SDK-Java.20\Bin" and click the up arrow until it is the first directory listed in the list box.

Or you can use the following steps instead:

  1. Back up your current Visual J++'s copy of Jvc.exe. You can locate this file in C:\Program Files\DevStudio\SharedIDE\bin.

  2. Then copy the following files from your SDK-Java.20\Bin directory (C:\SDK-Java.20\Bin) to C:\Program Files\DevStudio\SharedIDE\bin:

        - Jvc.exe
        - Jps.dll
        - Msjvc.dll.
    

STATUS

This behavior is by design.

MORE INFORMATION

The following is a check-list that you can use to trouble-shoot this problem if you are still seeing this error after upgrading to the Jvc.exe version 4337 or later.

  1. Make sure your DLL is visible on the system path. DLLs are searched for in the following locations (in order):

    a. The directory from which the application (typically jview) is loaded b. The current directory c. The Windows system directory d. The Windows directory e. The directories listed in the PATH environment variable

  2. The Microsoft Virtual Machine will not attempt to load the DLL until a method requiring it is actually called. Therefore, do not assume that the DLL load was successful simply because the Java class loaded successfully. Check the method qualifiers. Methods declared with the @dll.import directive must be native and static. They can have any level of access (public, private, and so on) supported by the Java language.

  3. Make sure that your method name matches the DLL export name exactly, including capitalization. The DLL linking mechanism in Win32 is case-sensitive.

  4. If you still have trouble linking to a method, use a utility such as dumpbin /exports (shipped with Visual C++) to verify that the DLL exports the method by the name you are using. Some DLLs may require you to link to exports by ordinal (an integer) rather than a name. In such a case, use the entrypoint override on the method using the "#ordinal" syntax as in the following example:

          // This method is exported as ordinal #34.
          /** @dll.import("MyDll",entrypoint="#34") */
          public static native void MySample();
    

  5. Be aware that some so-called functions are actually C macros and the actual DLL export name may be quite different from the name of the macro.

  6. Having a single @dll.import directive within a class definition, before all the method declarations inside that class, may also result in an UnsatisfiedLinkError. So try specifying the @dll.import prior to the class definition to set a library name for all native methods declared in that class. For example:

          /** @dll.import("KERNEL32") */
          class Test
         {
    
             public static native int GetEnvironmentStrings();
             public static native int GetEnvironmentVariable(String name,
                                                         StringBuffer value,
                                                         int ccbValue);
          }
    
    
This is equivalent to specifying @dll.import for each method. Also using the @dll.import directive at the class level saves space in the .class file and eliminates redundant information.

REFERENCES

For more information about J/Direct, see the following page on the Microsoft Web site:

   http://www.microsoft.com/java/sdk/

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, see the following page on the Microsoft Technical Support site:

   http://support.microsoft.com/support/visualj/
   http://support.microsoft.com/support/java/


Additional query words: J/Direct unsatisfiedlinkerror jvc
Keywords : kberrmsg JDirectX
Technology : kbInetDev internet
Version : WINDOWS:1.0,1.1,2.0,2.01
Platform : WINDOWS
Issue type : kbprb


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 10, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.