Skip to content

Dynamic libraries

This is mostly about using .so files on linux. Building them and windows may be added later.

linux

On linux, the program ldconfig is key. You can always force a dynamic library to be found with the LD_LIBRARY_PATH environment variable. :

LD_LIBRARY_PATH

LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/newdir

Or.. if it already contains a value :

add path
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/newdir

If you no run your program it will look in /newdir immediately for .so files. However we probably want a more permanent way of setting this variable.

/usr/local/lib

The GNU standards recommend installing by default all libraries in /usr/local/lib. The effect of that would be that you don't have to alter the ld path because it will be searched automatically.

You can view what the system sees as it's dynamic cache with

cache
sudo ldconfig -v

A snippet of this command shows it scans /usr/local/lib :

snippet
1
2
3
4
/usr/local/lib:
        libmongo-client.so.0 -> libmongo-client.so.0.4.1
        libbson-1.0.so.0 -> libbson-1.0.so.0.0.0
        libmongoc-1.0.so.0 -> libmongoc-1.0.so.0.0.0

So mongodb makes use of that location.

/etc/ld.so.conf.d

Maybe you want the .so file to be in you own installation dir, or maybe you just want to put the development directory to be scanned while developing code. You could add an extra entry (file) in /etc/ld.so.conf.d/ containing :

/etc/ld.so.conf.d/*
cat "/home/kees/projects/klopt/3pty/osrmlib/build" >> /etc/ld.so.conf.d/osrm.conf

Watch that this file has to end in .conf since the script that includes all these scripts is :

/etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf

Now still nothing happens until you run ldconfig, after that ldconfig -v will show :

ldconfig -v
1
2
3
4
5
6
/usr/local/lib:
    libmongo-client.so.0 -> libmongo-client.so.0.4.1
    libbson-1.0.so.0 -> libbson-1.0.so.0.0.0
    libmongoc-1.0.so.0 -> libmongoc-1.0.so.0.0.0
/home/kees/projects/klopt/3pty/osrmlib/build:
    libOSRM.so -> libOSRM.so