Loading dynamic lib into dynamic lib on Ubuntu

Ingo Foerster
Ingo Foerster used Ask the Experts™
I have some issues with Linux and loading dynamic libraries. In my case I load a library out of my app. This library is inside the same folder as my app. But now I want to load into this loaded library some libraries (plugins). But the system always report that it cannot find the library.
I am really new into this Linux world and so I want to find out my options to deal with it. My primary target is to have all dynamic libraries in the same folder to avoid problems.
Is there a way to use a C++ code to tell the software to search new libraries in the same path as the app is? I remember that this was possible on windows.

If I load the plugin I also use the full path to the library as well as the library name only.  
Any hint to deal with it? Or any further information needed?

Some data:
Ubuntu 64bit
C++ App compiled with C11 and Unicode
Bass Library, loaded with an dynamic interface, not with a static linked lib.
Bass Ape Plugin to test loading a Plugin.
Bass and Bassplugin are also 64 bit, same as my app.

The way I load the library, my app is cross platform, is working well on windows and on Mac, just on Linux I have the issue with the plugin.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

Notes about how to handle this...

1) You install your libraries in standard system paths.

For Debian/Ubuntu, you can list system paths...

net14 # cat /etc/ld.so.conf.d/*.conf
# libc default configuration
# Multiarch support

Open in new window

2) Best to use /usr/local/lib for placing libraries which are installed using handrolled builds, rather than installed by system packages (yum, apt-get, etc).

3) Be sure to run...


Open in new window

After you've deposited a new library into any system path.

4) Use this to ensure your library is actually seen by loader caching system.

ldconfig -p | grep your-library-name

5) Another approach, you can add your custom path to the ldconfig system, by adding a config file like...


Open in new window

Which contains a list of your library paths.

6) You can use RPATH magic. https://en.wikipedia.org/wiki/Rpath provides a lengthy explanation.

Tip: Best to use the loader path caching system (ldconfig), because once you have this setup, any code can dynamically load any library known to the ldconfig system, by name, rather than absolute path.
add the path where the libraries are to the environment variable LD_LIBRARY_PATH.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial