0

I'm currently starting to work with Shared Libraries under Linux (OpenSuse). The Shared Libraries I am writing are used by a bunch of small programs that provide some tools for electrical engineering. Thus the Libraries are very specific. Therefore I would like to keep the programs and the shared libraries in the users home directory.

Up to now I added the path of the project folder to /etc/ld.so.conf which works fine. There are just two problems.

First, the user needs root privileges to change the content of ld.so.conf which I would like to avoid. For the user it should be as easy as possible to run the software.

The second problem is, that the programs aren't running anymore if the user renames or moves the project folders (containing program and libraries). This might confuse some users.

Is there any way add a path to the dynamic linker without root privileges (I'm thinking of starting my application from a script that previously adds the current path to the dynamic linker)?

much
  • 47
  • 1
  • 1
  • 4

2 Answers2

1

Let the user modify /etc/ld.so.conf is definitely not the way to go.

A simple alternative would be to override LD_LIBRARY_PATH in the users shell init file (.bashrc, ...) or a more globally in /etc/environment.

Example: LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/YOUR_SHARED_LIB_PATH

An other alternative is to add the rpath option to the linker when compiling your application, that way the dynamic search path will include you directory when searching shared libraries.

But it is not recommended as it is not flexible (your directory moves, ...) and requires re-compiling.

dyslesia
  • 28
  • 1
  • 4
  • Thank you, I think the way using the LD_LIBRARY_PATH variable be an acceptable way to go. I'm now starting my application using the following shell script which currently works well for me. `#!/bin/bash PROGNAME=myprog BASEDIR=$(pwd) export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$BASEDIR DEPERROR=$(ldd testeseries | grep "not found") if [ "$DEPERROR" != "" ]; then echo "Dependency Error:" echo "Failed to load shared libraries needed for $PROGNAME" echo $DEPERROR else ./$PROGNAME fi` – much Feb 24 '15 at 13:05
0

You might set the LD_LIBRARY_PATH environment variable. You could even code some wrapping shell script (appropriately setting LD_LIBRARY_PATH) for each program.

You could also link with something like -Wl,-run-path

Read Drepper's paper: how to write shared libraries

BTW, you should decide for a fixed location for the libraries, perhaps $HOME/lib/ and avoid moving the directories containing them.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • If he wants to move the directories, rpath -- [http://stackoverflow.com/questions/26943102/how-to-set-runpath-of-a-binary] -- would not be helpful. – Thomas Dickey Feb 24 '15 at 12:09