Java Problem “UnsatisfiedLinkError”

前端 未结 5 943
遥遥无期
遥遥无期 2020-12-11 13:38

I made a simple java program that sends bytes to the parallel port, which uses a .dll along with two other classes (pPort.java and ioPort.java) to accomplish it, and it work

相关标签:
5条回答
  • 2020-12-11 13:46

    An UnsatisfiedLinkError message typically indicates that the library path is set but does not include the library that you are trying to load. On Windows platforms, you should extend the PATH using

    PATH = %PATH%;C:\path_to_dll_file 
    

    On UNIX platforms, you should extend the library path using

    setenv LD_LIBRARY_PATH mylibrarypath 
    

    However, as far as I can remember (I'm not under Windows), System32 is in the PATH so I suspect NetBeans to overwrite it by settings its own PATH.

    To solve this on NetBeans, you might want to check http://wiki.netbeans.org/DevFaqNativeLibraries which is mentioned in this message from Wade Chandler, a NetBeans Dream Team Member ;-)

    PS: You can also use the java.library.path system property but keep in mind that this system property only works to resolve the immediate native library that you are loading in your code. Loading of other dependent libraries is left to the first library. The JNI library that you load will rely on the OS dependent way to resolve its references (this applies to the solution of the FAQ too IMO so I'm still not 100% convinced its a good solution).

    0 讨论(0)
  • 2020-12-11 13:53

    In my case the cause was not the missing library, but the use of 64 bit Java JDK as default java platform for Netbeans.

    (It did not help to add the "-d32" flag.)

    The problem was solved by:

    1. Adding a 32 bit java platform to Netbeans (Menu: Tools/Java platforms) and
    2. Assigning it as the platform for the project (Project properties/Libraries/Java Platform).
    0 讨论(0)
  • 2020-12-11 13:54

    DLL needs to be in the path or current working directory in order to be loaded.

    I'm guessing when you've ran your program without IDE the latter was the case. When you run it from within NetBeans "working" directory is likely netbeans/bin folder, so DLL can't be found. Add its location to path and you should be good to go.

    0 讨论(0)
  • 2020-12-11 14:00

    Have you looked into the two classpaths for both programs (standalone and IDE) ?

    0 讨论(0)
  • 2020-12-11 14:01

    I don't do Netbeans, but it sounds like that Netbeans maintains its own java.library.path. Best what you could try is to specify it yourself as VM argument:

    -Djava.library.path="c:/path/to/dll/files"
    
    0 讨论(0)
提交回复
热议问题