我为Raspberry Pi 3上的交叉编译构建了Qt 5.9.4。一切都适用于测试应用程序。我的问题是:
在Qt Creator中创建了名为SlaveDeviceModels
的静态库。我将此库部署到raspberry并在rpi上运行此命令:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/pi/Documents/QtProjectsTests/SmartHomeServer
然后我创建了名为SmartHomeServer
的控制台应用程序项目,并将其添加到此项目外部库SlaveDeviceModels
中。然后我试图通过Qt Creator运行这个应用程序,但是我收到错误:
/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.
所以我转到rpi文件夹,它看起来如下:
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
然后我试图通过./SmartHomeServer
运行此应用程序,它运行正常。它开始了。
唯一的问题是我尝试从本地计算机上的Qt Creator启动SmartHomeServer
(交叉编译)。有没有人可以帮我解决问题所在。也许在Qt Creator中缺少设置?
这是我的SmartHomeServer.pro
文件:
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.
DEFINES += QT_DEPRECATED_WARNINGS
# 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
答案 0 :(得分:1)
解决方法是将这些代码行添加到.pro文件:
unix:!mac {
LIBS += -Wl,-rpath=\\\$$ORIGIN/libs
}
现在您可以将所有必需的库放在可执行文件的libs子文件夹中。
Windows或Mac不需要此方法。 请记住使用qt.conf文件作为Qt插件。 问候。