Link to home
Start Free TrialLog in
Avatar of Ingo Foerster
Ingo Foerster

asked on

Loading dynamic lib into dynamic lib on Ubuntu

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.
Avatar of David Favor
David Favor
Flag of United States of America image

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
/usr/lib/x86_64-linux-gnu/libfakeroot
# libc default configuration
/usr/local/lib
# Multiarch support
/usr/local/lib/x86_64-linux-gnu
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu

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...

ldconfig

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...

/etc/ld.so.conf.d/your-lib-paths.conf

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.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.