0

In Ubuntu 16, when setting environment variable like this, what we had in LD_LIBRARY_PATH before will be erased? I have already ROS and want to add the opencv<->numpy converter. I don't want to lose what I already have in LD_LIBRARY_PATH, though and everywhere I search I don't find if it edits what we have in env variable or just add new entries. Don't want to lose anything haha

Daniel Saito
  • 67
  • 1
  • 7

1 Answers1

1

Read about how ${LD_LIBRARY_PATH} is used like this:

$ man ld.so

You already know that ${PATH} is a list of directories that are polled when just an application name is given:

$ foo

and ${LD_LIBRARY_PATH} works exactly the same for the ld.so(1) dynamic library linker.

The tricky bit is that ld.so(1) uses a cache of the shared libraries found the last time the ${LD_LIBRARY_PATH} was used. This speeds up the program starting, just as any cache is supposed to do. Lots of examples show just mentioning a single directory to pick up an application-specific library:

$ export LD_LIBRARY_PATH=/my/wonderful/library
$ foo

but that is depending that the existing cache already any other needed library because the ld.so(1) will know to search only that "/my/wonderful/library/" location.

A better solution is to add the new directory like this:

$ export LD_LIBRARY_PATH=/my/wonderful/library:${LD_LIBRARY_PATH}
$ foo

which will work even if the ld.so(1) cache gets deleted out from under you and ldconfig(1) has to rebuild that cache.

This idiom that exports the ${LD_LIBRARY_PATH} permanently is a bad, bad idea:

$ export LD_LIBRARY_PATH=/my/wonderful/library:${LD_LIBRARY_PATH}
$ foo

because the custom ${LD_LIBRARY_PATH} will be used for the "foo" application plus any child program in this process tree. Instead, always limit the setting to process tree here instead of anything run from this shell ever again. Keep control of where the path is set like this:

$ LD_LIBRARY_PATH=/my/wonderful/library:${LD_LIBRARY_PATH} foo

limits visibility of the ${LD_LIBRARY_PATH} to only "foo" and any process it spawns.

  • so.. it's bad that I did `$ export LD_LIBRARY_PATH = ${LD_LIBRARY_PATH}:/module/i/am/trying/to/import` .. cause I couldn't make the module work doing this nor could find the damn `np_opencv_converter.so` that is required to run the module – Daniel Saito Jun 21 '21 at 12:35
  • oh, and what's the difference between the order : `LD_LIBRARY_PATH:/directory/of /module` or `/directory/of/module:LD_LIBRARY_PATH` – Daniel Saito Jun 21 '21 at 12:39