I create dynamic library by means of Qt. I collect it, in the end I have 4 files:

3 links to the library.

  1. libfigure.so
  2. libfigure.so.1
  3. libfigure.so.1.0

And the library itself.

  1. libfigure.so.1.0.0

I create a new project and connect the library through the menu (Add Library - External ... - I select the library and header files). Here is the .pro file:

QT += core QT -= gui TARGET = libDemo CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp unix:!macx: LIBS += -L$$PWD/../build-figure-Desktop_Qt_Debug/ -lfigure INCLUDEPATH += $$PWD/../figure DEPENDPATH += $$PWD/../figure 

When you run the program from Qt Creator, everything works. But when running in the terminal:

./libDemo: error while loading loading shared libraries:

Where should I put the library so that the program runs from the terminal?

  • In the same directory as ELF tried to put? - Vladimir Martyanov
  • I put all 4 files next to the main program. The same effect. - Anatoly Sivenko
  • Hmm ... libfigure.so.1 is in the directory with ELF and libfigure.so.1 points to libfigure.so.1.0.0, is there libfigure.so.1.0.0 along this path? Then the mystery is incomprehensible. - Vladimir Martyanov

2 answers 2

As an option - / usr / local / lib . After placing the library, you should run the ldconfig command under the superuser.

It is possible in / usr / lib but not worth it, it is better not to clutter up this directory manually.

Also libraries can be placed near the main program. In this case, the ldconfig command should specify the path where the library is located:

 ldconfig <path> 

Wherever the library is located, after each assembly, it is necessary to execute the ldconfig command.

  • That helped. But why the library itself is not picked up, as in Windows? - Anatoly Sivenko
  • Apparently, this is exactly how UNIX-like operating systems are organized. If automatic pickup is needed, then you can track changes in the necessary directories with the help of the inotify command and, if they are detected, run ldconfig. - sba

You can also add the path to your library in /etc/ld.so.conf and run ldconfig after building it. By the way, calling ldconfig after each reassembly is unnecessary, it is enough to call it once after the first build of your library, so that it will be included in the list of dynamically linked libraries in the system. Or you can modify the LD_LIBRARY_PATH environment variable when the application starts: LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/path/to/your/library" ./your_app