Shell Using shared libraries on external media

If I've installed an application on a USB stick, how would I run it if its shared libraries are also on the USB stick but in a different directory?

I'm guessing I would need to amend something like LD_LIBRARY_PATH, but I don't see such a variable in my environment.
 
If it is not set, then it uses the default load library path. So to add something else to it, the common syntax is: "export LD_LIBRARYPATH=${LD_LIBRARY_PATH}:/mnt/my_usb_stick/lib/libfoobar.so" (that example is in sh / bash syntax, it will be different for other shells). If it hasn't been set yet, you end up with ":/mnt/my_usb_stick/...", which is IMHO the correct way to set it: search standard paths first, then my own.

EDIT: No, don't do that, it exposes you to dangerously reading shared libraries from the current directory. Read the article that SirDice linked to below for how to do it right (with an if statement or a conditional string statement in the shell).

Look at "man ldconfig", it explains it.
 
Last edited:
the common syntax is: "export LD_LIBRARYPATH=${LD_LIBRARY_PATH}:/mnt/my_usb_stick/lib/libfoobar.so" (that example is in sh / bash syntax, it will be different for other shells). If it hasn't been set yet, you end up with ":/mnt/my_usb_stick/...", which is IMHO the correct way to set it:
If LD_LIBRARY_PATH is empty it actually adds your current working directory to LD_LIBRARY_PATH, which is a big no-no.

 
Back
Top