How do I get rid of LD_LIBRARY_PATH at run-time?

后端 未结 7 1132
温柔的废话
温柔的废话 2021-02-14 10:25

I am building a C++ application that uses Intel\'s IPP library. This library is installed by default in /opt and requires you to set LD_LIBRARY_PATH both for compil

相关标签:
7条回答
  • 2021-02-14 11:02

    As suggested by Richard Pennington, the missing library is not used directly by my application, but it is used by the shared libraries I use. Since I cannot recompile IPP, the solution to my problem is to add -liomp5 when compiling, using the -R option for the linker. This actually adds the rpath for libiomp5.so fixing the problem!

    0 讨论(0)
  • 2021-02-14 11:03

    By /path/to/lib do you mean path to the directory containing the library, or the path to the actual file?

    The -R option given a directory argument is treated like -rpath by ld, which is the option you're actually wanting here. It adds the given directory to the runtime library search path. That should work, as long as you give it the directory and not filename. I'm fairly confident about that, having done it myself, and because it's one of the hints given by libtool:

    Libraries have been installed in:

    /path/to/library-directory

    If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following:

    • add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution
    • add LIBDIR to the `LD_RUN_PATH' environment variable during linking
    • use the `-Wl,-rpath -Wl,LIBDIR' linker flag
    • have your system administrator add LIBDIR to `/etc/ld.so.conf'

    (I paste this here since conceivably one of the other options could be more desirable - for example LD_RUN_PATH can save you makefile modification)

    0 讨论(0)
  • 2021-02-14 11:07

    You can check if the path to the library is being picked up from your -R flag by running the ldd command or the readelf command on your binary. The LD_LIBRARY_PATH environment variable is an override, so shouldn't be necessary normally.

    0 讨论(0)
  • 2021-02-14 11:07

    You should use the -R option if possible.

    If not, rename your executable and create a launch script that runs your executable, and in there set LD_LIBRARY_PATH just for that scope.

    Depending on platform, you can modify ld.so.conf via /etc/ld.so.conf.d (Redhat/Fedora come to mind) which makes deploying changes to ld.so "easier" from a deployment scenario.

    0 讨论(0)
  • 2021-02-14 11:08

    Besides all the useful hints posted here.. you're not trying to use a 64-bit specific library on a 32-bit system (or viceversa, depending on other conditions), are you?

    0 讨论(0)
  • 2021-02-14 11:08

    bash:

    export LD_LIBRARY_PATH=/path/to/lib
    

    tcsh:

    setenv LD_LIBRARY_PATH /path/to/lib
    
    0 讨论(0)
提交回复
热议问题