Java.lang.UnsatisfiedLinkError:Can not load XXX library ... JNA cannot load DLL dynamic library problem

Source: Internet
Author: User

Java.lang.UnsatisfiedLinkError:Can not load XXX library ... JNA cannot load DLL dynamic library problem

1, version problem.

Version must correspond.

64-bit system, corresponding to 64 JDK or JRE, and corresponding dynamic libraries also need 64 bits.

32 bits also correspond so.

If you have two sets of JRE or JDK installed on your machine, such as 32 and 64 JRE at the same time, you will need to set the version of the JRE running on this computer to 64, specifically to set the Java version in the Control Panel's Java console.

Click Java, view, find and add operations. Ensure that 64-bit is enabled.


2, path problem.

1: Load DLL using JNA you first need to download Jna.jar, this jar file can be downloaded to the Sun website.

2:dllname This place can only be the name of the DLL, can not add ". dll" this is for cross-platform.

Using JNA typically encounters problems that cannot be loaded, typically due to the failure of the DLL file to be placed in the correct location.

The path can be set to an absolute or relative path.

Absolute path:

TestDll1 INSTANCE = (TestDll1) native.loadlibrary ("D:\\test\\testdll1", Testdll1.class);

Then the DLL is placed under the test folder under D disk.

Relative path:

In a Web service, you can put it under the Web-inf res folder

  String Realpath = Contextloader.getcurrentwebapplicationcontext (). Getservletcontext (). Getrealpath ("WEB-INF/res/ TestDll1.dll "); 
  String Path =realpath.substring (0,realpath.length ()-4);
  TestDll1 INSTANCE = (TestDll1) native.loadlibrary (path, testdll1.class);

PS: Cross-platform writing

Usually we use JNA in the following way (assuming DLL name is HelloDll.dll)

Interface Hellodll extends Library {
   TestDll1 INSTANCE = (TestDll1) native.loadlibrary ("Driver/testdll1", TestDll1. Class);
   public void Hello ();
}

1. In this case, we need to copy the TestDll1 file to the driver directory.

2. In order to cross the platform at the same time, the relative path should be written like this:

"Driver" + file.separator + "TestDll1"

3. Also, if TestDll1. dll relies on other packages, copy the package to the driver directory or the system path. There are a lot of tools for viewing DLL dependencies, so Google will do it.

Reference:

After the above steps, the basic can be solved, if not yet, refer to the following steps:

1:dll files to be placed under the project path;

2: Put the DLL file into the library file path, execute this code System.out.println (System.getproperty ("Java.library.path"));

Then copy the DLL file to any one of the paths

3:dll name does not seem to have "_" (This is my own encounter a problem, for reference only)

Note that these three points basically solve all the problems of using JNA to load C++,delphi,c DLLs.

Link:

Http://blog.sina.com.cn/s/blog_b7c09bc00101d2sk.html

http://blog.csdn.net/zhhniyniy/article/details/7968752

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.