Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to include shared library?



  • I have a console application that runs in Qt Creator. However when I try to run it in the terminal I get an error concerning a library:

    error while loading shared libraries: libCbcSolver.so.0: cannot open shared object file: No such file or directory
    

    The "pro" file has the lines to link to the library:

    LIBS += -L/home/daniel/Documents/COINOR/Cbc-2.10/build/lib -lCbc -lCbcSolver
    INCLUDEPATH += /home/daniel/Documents/COINOR/Cbc-2.10/build/include/coin
    

    Is there a way to include the shared library into the executable? So there is no need for:

    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/daniel/Documents/COINOR/Cbc-2.10/build/lib
    export LD_LIBRARY_PATH
    

  • Lifetime Qt Champion

    @Guerrian said in How to include shared library?:

    Is there a way to include the shared library into the executable?

    Either build the lib as static libs or add the library code to your project.

    But actually you should simply deploy your app with all needed libs properly: https://doc.qt.io/qt-5/linux-deployment.html



  • On Linux try to use
    unix:!mac {
    LIBS += -Wl,-rpath=\$$ORIGIN/libs
    }
    makes portable your application


Log in to reply