Shared Libraries in Same Folder with App in Tcsh

Shared Libraries in Same Folder with App in TCSH

Two simple options.

  1. You can set the LD_LIBRARY_PATH variable inside your script (see Section 3.3.1. of the shared libraries HOWTO). There are problems with this approach for production code, but if set in a wrapper script is probably ok.

  2. You can call your app with the libraries specified on the command line by invoking the ld-linux program loader directly, as described in the manpage and HOWTO:

    /lib/ld-linux.so.2 --library-path PATH EXECUTABLE

Porting a Unix program from one host to another

I think your best bet, given the circumstances, is to compile a static binary; see the -static option of gcc. However, this has downsides and might not always work.

You could also try to copy the shared libraries, but then you need to instruct the dynamic loader to search for the libraries in the location where you added them (your binary will have to be linked with the -Wl,-rpath,/path/to/libs switch.

Try the -static first. It should be easier.

If you wanna take a deeper look into the issues of binary portability, check out sources like:

  • http://www.evanjones.ca/portable-linux-binaries.html
  • http://freegamedev.net/wiki/Portable_binaries
  • Compiling C++ into portable linux binaries
  • google "linux binary portability"

Why do I have to define LD_LIBRARY_PATH with an export every time I run my application?

Use

export LD_LIBRARY_PATH="/path/to/library/"

in your .bashrc otherwise, it'll only be available to bash and not any programs you start.

Try -R/path/to/library/ flag when you're linking, it'll make the program look in that directory and you won't need to set any environment variables.

EDIT: Looks like -R is Solaris only, and you're on Linux.

An alternate way would be to add the path to /etc/ld.so.conf and run ldconfig. Note that this is a global change that will apply to all dynamically linked binaries.

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

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!

Will an executable moved to another directory still work?

As long as the executable can find it's dependencies (other dlls on Windows for example) then it will work. If it can't for any reason (i.e. it assumes that they are in the same directory) then it won't.

Unfortunately the error messages you get out of Windows aren't always the most helpful so you might have problems locating all the required files.



Related Topics



Leave a reply



Submit