2

I have compiled a library and now I should run ldconfig. However, I would rather not modify /etc/ld.so.conf, nor any other system file. Is it possible to generate the cache somewhere else and then make it visible only while compiling selected programs? Or should I manually set LD_LIBRARY_PATH and LD_RUN_PATH for this purpose?

2

You can check for option -f of ldconfig:

-f conf
Use conf instead of /etc/ld.so.conf.

If you run:

ldconfig -f custom.conf

with user with enough privileges it will modify /etc/ld.so.cache. ld reads /etc/ld.so.cache and I don't think you can make it to read from different file.

As you don't want to modify system files you can do following:

gcc -W -Wall -L/path_to_your_library -lyour_library test.c -o testo

to build your testo.c

Then:

export LD_LIBRARY_PATH=/path_to_your_library

to run it although setting of LD_LIBRARY_PATH help with debugging and to try out a newer version of a library its usage in the general development environment setup and deployment is considered bad. More you can check here.

Another approach could be using rpath:

unset LD_LIBRARY_PATH
gcc -L/path_to_your_library -Wl,-rpath=/path_to_your_library -W -Wall -o testo testo.c -lyour_library

With rpath method each program gets to list its shared library locations independently. Downsides: shared libraries should be installed in a fixed location. Also I've not tested but may be issues if library refers to a NFS mount.

  • Thanks. But then, how will I make that cache visible to ld? With the @file option of ld, maybe? – Elena Jul 1 '15 at 10:05
  • If you run ldconfig -f custom.conf as root it will modify /etc/ld.so.cache and it should be visisble. ld reads ld.so.cache and I don't think you can make it to read from different file, though with option -C of ldconfig you can create different cache file. – taliezin Jul 1 '15 at 10:28
  • But that would be exactly what I am trying to avoid: changing system files. Maybe I could set the -L and -l options of GCC, instead, basically doing by hand what ld does? – Elena Jul 1 '15 at 10:42
  • @Elena, answer edited. – taliezin Jul 1 '15 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.