Nominate our 2022 Qt Champions!

Deploy shared library to raspberry

  • Goodmorning,
    I've made a Subdir project with a shared library and a qt quick projects in it.
    The .pro file of the shared library is:

    # Project created by QtCreator 2016-04-16T15:08:40
    QT       += sql
    QT       -= gui
    TARGET = gallery-core
    TEMPLATE = lib
    CONFIG += lib c++11
    SOURCES += \
        AlbumModel.cpp \
        DatabaseManager.cpp \
        Album.cpp \
        Picture.cpp \
        PictureModel.cpp \
        AlbumDao.cpp \
    HEADERS += \
        gallery-core_global.h \
        AlbumModel.h \
        DatabaseManager.h \
        Album.h \
        Picture.h \
        PictureModel.h \
        AlbumDao.h \

    The qt quick .pro file is:

    TEMPLATE = app
    QT += qml quick sql svg
    CONFIG += c++11
    SOURCES += main.cpp \
    RESOURCES += gallery.qrc
    LIBS += -L$$OUT_PWD/../gallery-core/ -lgallery-core
    INCLUDEPATH += $$PWD/../gallery-core
    DEPENDPATH += $$PWD/../gallery-core
    HEADERS += \
    contains(ANDROID_TARGET_ARCH,x86) {
    # Default rules for deployment.
    target.path = /home/davide
    INSTALLS += target

    The problem that I'm facing is that qt deploys correctly the application but it launches the following error:
    /home/davide/gallery-mobile: error while loading shared libraries: cannot open shared object file: No such file or directory

    Basically the app is deployed on raspberry but the library .so doesn't.
    I tried using static shared library but it doesn't change a thing.
    Can you suggest me modifications for transfer the library file as well?

    Thank you.

  • Lifetime Qt Champion

    Hi @davidino,

    You have the following lines in your program project file:

    target.path = /home/davide
    INSTALLS += target

    But they seem to be missing in the librarys project file and therefore Creator does not deploy the library.


  • Hello aha_1980, thank you for your answer.
    I tried to add the lines suggested but I get the same error.
    I tried to add only in the .pro of the library and/or in the file of the Subdir project but unsuccessfully.
    I think there is another way for adding shared library to target

  • Lifetime Qt Champion

    @davidino said in Deploy shared library to raspberry:

    I think there is another way for adding shared library to target

    No, it isn't. You have to add these lines in all *.pro files defining a target (be it library or application). Please check Creators compile output when deploying to the target.

    You have of course to make sure, the app finds its library on the target, i.e. it is in a directory the dynamic linker will pick it up.

  • Hello aha_1980,
    thank you very much, I was wrong. It was sufficient to add :

    Default rules for deployment.

    target.path = /usr/lib
    INSTALLS += target
    So that the app could find the library deployed in /usr/lib.
    One last question: Since /usr/lib is the same folder as qt standard library, is there a way to let the app search the library in its very folder.
    Thank you again.

  • @davidino Yes, you can use LD_LIBRARY_PATH for this. I usually just make a startup script for my app that looks something like:

    exec ./myapp "$@"

    That should look for libs in . which is the same dir as your binary ./myapp.

    You can test this on the command line without a script with:

    $ LD_LIBRARY_PATH=. ./myapp

  • Hello, thank you to all.
    Now it works as I wanted.

Log in to reply