What is LD_LIBRARY_PATH and how to use it?
Asked Answered
A

6

66

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?

Adele answered 22/8, 2011 at 13:15 Comment(4)
google: "java.library.path"... click on any link that talks of this and dll...Hydrocellulose
and here's one I did earlier: inonit.com/cygwin/jni/helloWorld/load.htmlHydrocellulose
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.Carty
where is LD_LIBRARY_PATH? how do I set the LD_LIBRARY_PATH env variable? - Unix & Linux Stack ExchangeRetake
D
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
Daguerre answered 22/8, 2011 at 13:24 Comment(2)
mmm... but... what is LD_LIBRARY_PATH?Mc
See #27945768Stableboy
C
114

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.

Circassia answered 22/8, 2011 at 13:19 Comment(2)
i have a problem plz help me too https://superuser.com/questions/1396481/java-application-not-picking-up-app-properties-on-widows-10Profession
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.Herat
D
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
Daguerre answered 22/8, 2011 at 13:24 Comment(2)
mmm... but... what is LD_LIBRARY_PATH?Mc
See #27945768Stableboy
R
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).

Ravenravening answered 22/8, 2011 at 13:22 Comment(5)
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 :)Adele
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.Ravenravening
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. linuxmafia.com/faq/Admin/ld-lib-path.htmlZielinski
@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?Ravenravening
i have a problem plz help me https://superuser.com/questions/1396481/java-application-not-picking-up-app-properties-on-widows-10Profession
R
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.

Reconvert answered 4/7, 2018 at 7:29 Comment(0)
T
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.

Thibeault answered 4/7, 2018 at 5:59 Comment(0)
S
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

Skricki answered 22/8, 2011 at 13:25 Comment(1)
After the JVM startup you can't set java.library.path in this way.Lange

© 2022 - 2024 — McMap. All rights reserved.