Search code examples
c++gccboostldd

Linking against boost libraries


I'm having trouble building/running with some boost shared libraries.

Compilation works:

$ g++ -l boost_filesystem -l boost_program_option
$

But runtime fails:

$ ./a.out 
./a.out: error while loading shared libraries: libboost_filesystem.so.1.80.0: cannot open shared object file: No such file or directory

As expected, ldd complains:

$ ldd a.out 
        ...
        libboost_filesystem.so.1.80.0 => not found
        libboost_program_options.so.1.80.0 => not found
        ...

But, adapting the recipe offered here, ldd appears to include /usr/local/lib:

$ ldconfig -v |& grep "/usr/local/lib:"
/usr/local/lib: (from /etc/ld.so.conf.d/libc.conf:2)

And /usr/local/lib/ contains the required libraries:

$ ls -l /usr/local/lib/libboost_filesystem.so*
lrwxrwxrwx 1 root root     29 Oct 26 16:45 /usr/local/lib/libboost_filesystem.so -> libboost_filesystem.so.1.80.0
-rwxr-xr-x 1 root root 191992 Oct 26 16:45 /usr/local/lib/libboost_filesystem.so.1.80.0

So my question is, why am I getting this error?


Solution

  • It turns out that that ldd uses a system cache, and that this cache needs to be explicitly updated via:

    sudo ldconfig
    

    Doing this resolved my issue.