63

I take part in developing a Java project, which uses some C++ components, thus I need Jacob.dll. (on Windows 7)

I keep getting java.lang.UnsatisfiedLinkError: no JacobDB in java.library.path no matter where I put Jacob.dll....

I looked for possible decisions and the one that I haven't tried so far is setting the LD_LIBRARY_PATH variable, pointing at the .dll file.

I have little experience and I'm not familiar with what should be the meaning and usage of that variable - can you help me?

Neuron
  • 5,141
  • 5
  • 38
  • 59
karla
  • 4,506
  • 5
  • 34
  • 39
  • google: "java.library.path"... click on any link that talks of this and dll... – Nim Aug 22 '11 at 13:18
  • 1
    and here's one I did earlier: http://www.inonit.com/cygwin/jni/helloWorld/load.html – Nim Aug 22 '11 at 13:19
  • 2
    If you are using windows and need to have that dll loaded, use the "PATH" system variable or drop the dll in the Windows/System32 directory. LD_LIBRARY_PATH is not used in windows. – Paul Gregoire Aug 27 '14 at 14:48
  • [where is LD_LIBRARY_PATH? how do I set the LD_LIBRARY_PATH env variable? - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/168340/where-is-ld-library-path-how-do-i-set-the-ld-library-path-env-variable) – user202729 Sep 02 '18 at 07:08

6 Answers6

109

LD_LIBRARY_PATH is the predefined environmental variable in Linux/Unix which sets the path which the linker should look in to while linking dynamic libraries/shared libraries.

LD_LIBRARY_PATH contains a colon separated list of paths and the linker gives priority to these paths over the standard library paths /lib and /usr/lib. The standard paths will still be searched, but only after the list of paths in LD_LIBRARY_PATH has been exhausted.

The best way to use LD_LIBRARY_PATH is to set it on the command line or script immediately before executing the program. This way the new LD_LIBRARY_PATH isolated from the rest of your system.

Example Usage:

$ export LD_LIBRARY_PATH="/list/of/library/paths:/another/path"
$ ./program

Since you talk about .dll you are on a windows system and a .dll must be placed at a path which the linker searches at link time, in windows this path is set by the environmental variable PATH, So add that .dll to PATH and it should work fine.

Alok Save
  • 202,538
  • 53
  • 430
  • 533
  • i have a problem plz help me too `https://superuser.com/questions/1396481/java-application-not-picking-up-app-properties-on-widows-10` – Arash Jan 21 '19 at 19:03
  • Regarding isolation, the export you have would also affect any subsequent commands run after `./program`. You can avoid this by setting the environment variable only for the command. You can do this by adding it to the same line: `LD_LIBRARY_PATH="/list/of/library/paths:/another/path" ./program`. – mattalxndr Jan 07 '22 at 20:36
20

Typically you must set java.library.path on the JVM's command line:

java -Djava.library.path=/path/to/my/dll -cp /my/classpath/goes/here MainClass
hmakholm left over Monica
  • 23,074
  • 3
  • 51
  • 73
15

LD_LIBRARY_PATH is Linux specific and is an environment variable pointing to directories where the dynamic loader should look for shared libraries.

Try to add the directory where your .dll is in the PATH variable. Windows will automatically look in the directories listed in this environment variable. LD_LIBRARY_PATH probably won't solve the problem (unless the JVM uses it - I do not know about that).

Neuron
  • 5,141
  • 5
  • 38
  • 59
Markus Pilman
  • 3,104
  • 3
  • 22
  • 31
  • Thank you, obviously it is not going to work for me. Otherwise adding the item to PATH variable was something I did in first place...with no luck so far :) – karla Aug 22 '11 at 13:24
  • I am not a Java developer, but could you try out to print the java.library.path variable (with System.getProperty())? You could also try to set this variable with the -D command line flag when starting the VM - may be even setting this at runtime could work. If you are working in Eclipse imho there is a way to set something like "Native Library locations" in the Build Path setting in the project properties. – Markus Pilman Aug 22 '11 at 13:29
  • 3
    Not Linux!! All Unixes use this environment variable! Also it is not for linking, but for loading! Static linked libraries are usually given on the command line to the linker, dynamic loaded ones get looked up via LD_LIBRARY_PATH. See e.g. http://linuxmafia.com/faq/Admin/ld-lib-path.html – Angel O'Sphere Aug 22 '11 at 13:37
  • 1
    @Angel O'Sphere: 1st: the dynamic linker will use this for loading. 2nd: Mac OS X uses DYLD_LIBRARY_PATH. Granted: LD_LIBRARY_PATH is not Linux specific but I think in the context of the question this is pettifoggery. Ah and btw: I wrote about loading - so where do you see anything about linking and LD_LIBRARY_PATH in my comment? – Markus Pilman Aug 22 '11 at 13:44
  • i have a problem plz help me `https://superuser.com/questions/1396481/java-application-not-picking-up-app-properties-on-widows-10` – Arash Jan 21 '19 at 19:03
4

LD_LIBRARY_PATH is the default library path which is accessed to check for available dynamic and shared libraries. It is specific to linux distributions.

It is similar to environment variable PATH in windows that linker checks for possible implementations during linking time.

Shrikanth N
  • 652
  • 3
  • 17
2

My error was also related to not finding the required .so file by a service. I used LD_LIBRARY_PATH variable to priorities the path picked up by the linker to search the required lib.

I copied both service and .so file in a folder and fed it to LD_LIBRARY_PATH variable as

LD_LIBRARY_PATH=. ./service

being in the same folder I have given the above command and it worked.

alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
1

Well, the error message tells you what to do: add the path where Jacob.dll resides to java.library.path. You can do that on the command line like this:

java -Djava.library.path="dlls" ...

(assuming Jacob.dll is in the "dlls" folder)

Also see java.lang.UnsatisfiedLinkError no *****.dll in java.library.path

Community
  • 1
  • 1
daniel kullmann
  • 13,653
  • 8
  • 51
  • 67