Posts: 2
Joined: Wed Mar 07, 2018 11:07 pm

Qt project with custom shared library cross compile

Sat Mar 17, 2018 3:05 pm

I built Qt 5.9.4 for cross-compile on Raspberry Pi 3. Everything works fine with test applications. My problem is following:

Created static library in Qt Creator which is named `SlaveDeviceModels`. I deployed this library to raspberry and run this command on rpi:

Code: Select all

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/pi/Documents/QtProjectsTests/SmartHomeServer
Then I created console application project which is named `SmartHomeServer` and added to this project external library `SlaveDeviceModels`. Then I tried to run this application through Qt Creator but I get error:

Code: Select all

/home/pi/Documents/QtProjectsTests/SmartHomeServer/SmartHomeServer: error while loading shared libraries: libSlaveDeviceModels.so.1: cannot open shared object file: No such file or directory
    Application finished with exit code 127.
So I go to rpi folder and it looks following:

Code: Select all

pi@raspberrypi:~/Documents/QtProjectsTests/SmartHomeServer $ ls -l
    total 3048
    -rwxr-xr-x 1 pi pi 2122400 Mar 17 14:10 SmartHomeServer
    -rw-r--r-- 1 pi pi    9006 Mar 17 14:04 SmartHomeServer.log
    lrwxrwxrwx 1 pi pi      29 Mar 17 13:28 libSlaveDeviceModels.so -> libSlaveDeviceModels.so.1.0.0
    lrwxrwxrwx 1 pi pi      29 Mar 17 13:28 libSlaveDeviceModels.so.1 -> libSlaveDeviceModels.so.1.0.0
    lrwxrwxrwx 1 pi pi      29 Mar 17 13:28 libSlaveDeviceModels.so.1.0 -> libSlaveDeviceModels.so.1.0.0
    -rwxr-xr-x 1 pi pi  980428 Mar 17 13:28 libSlaveDeviceModels.so.1.0.0

Then I tried to run this app by `./SmartHomeServer` and it worked fine. It started.

Only problem is when I'm trying to start `SmartHomeServer` from Qt Creator on my local computer (cross-compile). Does anyone can help me where might be problem. Maybe missing settings in Qt Creator?

This is my `SmartHomeServer.pro` file:

Code: Select all

QT += core
    QT -= gui
    CONFIG += c++11
    TARGET = SmartHomeServer
    CONFIG += console
    CONFIG -= app_bundle
    TEMPLATE = app
    SOURCES += main.cpp
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which as been marked deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    # Default rules for deployment.
    target.path = /home/pi/Documents/QtProjectsTests/SmartHomeServer
    INSTALLS += target
    # here are included my headers
    INCLUDEPATH += $$PWD/../SlaveDeviceModels
    # I tried do something like that
    #LIBS += -L/home/pi/Documents/QtProjectsTests/SmartHomeServe -lSlaveDeviceModels
    # that are default lines added by qt creator
    unix:!macx: LIBS += -L$$PWD/../build-SlaveDeviceModels-Raspberry_Pi_3_Kit-Debug/ -lSlaveDeviceModels
    INCLUDEPATH += $$PWD/../build-SlaveDeviceModels-Raspberry_Pi_3_Kit-Debug
    DEPENDPATH += $$PWD/../build-SlaveDeviceModels-Raspberry_Pi_3_Kit-Debug

User avatar
Posts: 4263
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Qt project with custom shared library cross compile

Mon Mar 19, 2018 10:03 am

If its a .so file and you are messing with LD_LIBRARY_PATH then its a *dynamic* library, not a static one.

Environment variables created with "export" command is still only valid in that shell instance.

I would maybe suggest that you copy the files to "/usr/local/lib" and run "sudo ldconfig" and then see if the files are found by using the "ldd" command on your binary.

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 5 guests