参考网址:
Ubuntu快速打包发布Qt应用程序
https://blog.csdn.net/q357010621/article/details/98885618
ubuntu 升级QT版本后,在新机上发布QT程序报错:qt.qpa.plugin: Could not find the Qt platform plugin “xcb” in “”
https://blog.csdn.net/AAA123524457/article/details/103239301?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.control
https://blog.csdn.net/lusanshui/article/details/84988017?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control
https://blog.csdn.net/JIEJINQUANIL/article/details/107007814
https://blog.csdn.net/u010847928/article/details/91442388?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-6.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-6.control
前段时间需要在linux下开发QT的串口程序,有一块板子已经
安装好QT作为调试机,需要打包给没装开发环境的板子做测试
打包步骤如下:
1)使用QT编译完之后在debug/release文件夹下得到可执行文件如demo
2)新建一个文件夹如demoPack,把demo拷贝这个地方
3)新建一个脚本文件pack.sh,作用是提取lib文件,内容如下:
#!/bin/sh
exe="demo" #你需要发布的程序名称
des="/home/admin1/demoPack" #创建文件夹的位置
deplist=$(ldd $exe | awk '{if (match($3,"/")){ printf("%s "),$3 } }')
cp $deplist $des
4)新建一个脚本文件demo.sh,内容如下
#!/bin/sh
appname=`basename $0 | sed s,\.sh$,,`
dirname=`dirname $0`
tmp="${dirname#?}"
if [ "${dirname%$tmp}" != "/" ]; then
dirname=$PWD/$dirname
fi
LD_LIBRARY_PATH=$dirname
export LD_LIBRARY_PATH
$dirname/$appname "$@"
文件夹如下图:
5)在当前文件夹鼠标右键打开终端,输入./pack.sh
如果遇到权限不够,输入chmod 777 pack.sh,在执行./pack.sh
执行成功之后会得到依赖的lib文件,如图:
6)测试是否可以执行,在终端输入./demo.sh,遇到的问题可能会有
如果遇到权限不够,可以使用chmod命令对shell脚本赋予权限
如: chmod 777 ./demo.sh;
如果遇到执行遇到Permission denied,是文件夹权限的问题,
输入如:sudo chmod -R 777 当前文件夹路径
7)这个文件夹就可以在未安装QT的板子上测试使用
ubuntu 升级QT版本后,在新机上发布QT程序报错:qt.qpa.plugin: Could not find the Qt platform plugin “xcb” in “”
本地原本使用的QT版本是5.11,最近更新成了5.13.2;在本地编译、运行一切正常;发布release版本到新的ubuntu上;由于在新机器上没有安装QT,所以发布的时候通过ldd导致出程序的依赖库,把这些依赖库和程序放在同一目录一起拷贝到新机器上,初次运行需要指定库目录,否则会报找不到库文件的错误:
指定程序执行的库文件目录,在终端输入指令:
export LD_LIBRARY_PATH='/home/rdd/pp':$LD_LIBRARY_PATH
然后再重新运行程序,结果运行时出现错误:
猜测是运行依赖库不全导致,但是一开始通过ldd导出的依赖库在编译程序的机器上已经是完整的,所以这里应该是内部库的二次依赖导致。启动QT_DEBUG_PLUGINS,查看程序的执行过程,分析是哪部分缺失。也可以通过设置环境变量的方式,不过如果只是调bug,只需要在终端输入,让其一次性显示即可,在终端输入指令:
export QT_DEBUG_PLUGINS=1
然后再重新启动发布的程序,发现多了一点打印信息:
提示在程序的执行目录下,企图加载platforms的相关库,以打印相关的库调用信息,但是这里并没有相关打印。是因为当前缺少platforms目录的库文件导致。
从原机器上(装了QT5.13.2)的QT安装目录中,把该目录以及其内部所有文件完整拷贝到新机器上(xftp拷贝),我的安装在OPT目录,里面的库文件只有12个,需要把完整目录一起拷贝到新机器的程序同目录下,完整目录如下:
然后再回到新机器上,重新执行程序(前面的设置步骤要先设置好),然后就有完整的debug信息出来了
QFactoryLoader::QFactoryLoader() checking directory path “/home/rdd/pp/platforms” …
QFactoryLoader::QFactoryLoader() looking at “/home/rdd/pp/platforms/libqeglfs.so”
Found metadata in lib /home/rdd/pp/platforms/libqeglfs.so, metadata=
{
“IID”: “org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3”,
“MetaData”: {
“Keys”: [
“eglfs”
]
},
“archreq”: 0,
“className”: “QEglFSIntegrationPlugin”,
“debug”: false,
“version”: 331008
}
Got keys from plugin meta data (“eglfs”)
QFactoryLoader::QFactoryLoader() looking at “/home/rdd/pp/platforms/libqlinuxfb.so”
Found metadata in lib /home/rdd/pp/platforms/libqlinuxfb.so, metadata=
{
“IID”: “org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3”,
“MetaData”: {
“Keys”: [
“linuxfb”
]
},
“archreq”: 0,
“className”: “QLinuxFbIntegrationPlugin”,
“debug”: false,
“version”: 331008
}
Got keys from plugin meta data (“linuxfb”)
QFactoryLoader::QFactoryLoader() looking at “/home/rdd/pp/platforms/libqminimal.so”
Found metadata in lib /home/rdd/pp/platforms/libqminimal.so, metadata=
{
“IID”: “org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3”,
“MetaData”: {
“Keys”: [
“minimal”
]
},
“archreq”: 0,
“className”: “QMinimalIntegrationPlugin”,
“debug”: false,
“version”: 331008
}
Got keys from plugin meta data (“minimal”)
QFactoryLoader::QFactoryLoader() looking at “/home/rdd/pp/platforms/libqminimalegl.so”
Found metadata in lib /home/rdd/pp/platforms/libqminimalegl.so, metadata=
{
“IID”: “org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3”,
“MetaData”: {
“Keys”: [
“minimalegl”
]
},
“archreq”: 0,
“className”: “QMinimalEglIntegrationPlugin”,
“debug”: false,
“version”: 331008
}
Got keys from plugin meta data (“minimalegl”)
QFactoryLoader::QFactoryLoader() looking at “/home/rdd/pp/platforms/libqoffscreen.so”
Found metadata in lib /home/rdd/pp/platforms/libqoffscreen.so, metadata=
{
“IID”: “org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3”,
“MetaData”: {
“Keys”: [
“offscreen”
]
},
“archreq”: 0,
“className”: “QOffscreenIntegrationPlugin”,
“debug”: false,
“version”: 331008
}
Got keys from plugin meta data (“offscreen”)
QFactoryLoader::QFactoryLoader() looking at “/home/rdd/pp/platforms/libqvnc.so”
Found metadata in lib /home/rdd/pp/platforms/libqvnc.so, metadata=
{
“IID”: “org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3”,
“MetaData”: {
“Keys”: [
“vnc”
]
},
“archreq”: 0,
“className”: “QVncIntegrationPlugin”,
“debug”: false,
“version”: 331008
}
Got keys from plugin meta data (“vnc”)
QFactoryLoader::QFactoryLoader() looking at “/home/rdd/pp/platforms/libqwayland-egl.so”
Found metadata in lib /home/rdd/pp/platforms/libqwayland-egl.so, metadata=
{
“IID”: “org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3”,
“MetaData”: {
“Keys”: [
“wayland-egl”
]
},
“archreq”: 0,
“className”: “QWaylandEglPlatformIntegrationPlugin”,
“debug”: false,
“version”: 331008
}
Got keys from plugin meta data (“wayland-egl”)
QFactoryLoader::QFactoryLoader() looking at “/home/rdd/pp/platforms/libqwayland-generic.so”
Found metadata in lib /home/rdd/pp/platforms/libqwayland-generic.so, metadata=
{
“IID”: “org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3”,
“MetaData”: {
“Keys”: [
“wayland”
]
},
“archreq”: 0,
“className”: “QWaylandIntegrationPlugin”,
“debug”: false,
“version”: 331008
}
Got keys from plugin meta data (“wayland”)
QFactoryLoader::QFactoryLoader() looking at “/home/rdd/pp/platforms/libqwayland-xcomposite-egl.so”
Found metadata in lib /home/rdd/pp/platforms/libqwayland-xcomposite-egl.so, metadata=
{
“IID”: “org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3”,
“MetaData”: {
“Keys”: [
“wayland-xcomposite-egl”
]
},
“archreq”: 0,
“className”: “QWaylandXCompositeEglPlatformIntegrationPlugin”,
“debug”: false,
“version”: 331008
}
Got keys from plugin meta data (“wayland-xcomposite-egl”)
QFactoryLoader::QFactoryLoader() looking at “/home/rdd/pp/platforms/libqwayland-xcomposite-glx.so”
Found metadata in lib /home/rdd/pp/platforms/libqwayland-xcomposite-glx.so, metadata=
{
“IID”: “org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3”,
“MetaData”: {
“Keys”: [
“wayland-xcomposite-glx”
]
},
“archreq”: 0,
“className”: “QWaylandXCompositeGlxPlatformIntegrationPlugin”,
“debug”: false,
“version”: 331008
}
Got keys from plugin meta data (“wayland-xcomposite-glx”)
QFactoryLoader::QFactoryLoader() looking at “/home/rdd/pp/platforms/libqwebgl.so”
Found metadata in lib /home/rdd/pp/platforms/libqwebgl.so, metadata=
{
“IID”: “org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3”,
“MetaData”: {
“Keys”: [
“webgl”
]
},
“archreq”: 0,
“className”: “QWebGLIntegrationPlugin”,
“debug”: false,
“version”: 331008
}
Got keys from plugin meta data (“webgl”)
QFactoryLoader::QFactoryLoader() looking at “/home/rdd/pp/platforms/libqxcb.so”
Found metadata in lib /home/rdd/pp/platforms/libqxcb.so, metadata=
{
“IID”: “org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3”,
“MetaData”: {
“Keys”: [
“xcb”
]
},
“archreq”: 0,
“className”: “QXcbIntegrationPlugin”,
“debug”: false,
“version”: 331008
}
Got keys from plugin meta data (“xcb”)
Cannot load library /home/rdd/pp/platforms/libqxcb.so: (/usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5: version Qt_5_PRIVATE_API' not found (required by /home/rdd/pp/platforms/libqxcb.so)) QLibraryPrivate::loadPlugin failed on "/home/rdd/pp/platforms/libqxcb.so" : "Cannot load library /home/rdd/pp/platforms/libqxcb.so: (/usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5: version
Qt_5_PRIVATE_API’ not found (required by /home/rdd/pp/platforms/libqxcb.so))"
qt.qpa.plugin: Could not load the Qt platform plugin “xcb” in “” even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.
已放弃 (核心已转储)
直接跳到log的最后,发现了出现错误的地方:
Cannot load library /home/rdd/pp/platforms/libqxcb.so: (/usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5: version `Qt_5_PRIVATE_API' not found (required by /home/rdd/pp/platforms/libqxcb.so))
缺失库文件:libQt5XcbQpa.so.5。
知道明确缺失哪个文件就好办了:再回到原机器上(装了QT5.13.2),在QT安装目录下:
拷贝到新机器的程序执行目录下,然后再启动程序,就没有再报错了!到此,这个xcb的报错问题已经成功解决!
需要注意的问题:
另外需要特别注意一个问题,就是这些.so.5结尾的文件,在原机器上,都只是一个链接文件,它链接到一个目标文件,这个目标文件才是真正的库文件,如果只是拷贝一个链接文件过去,是无法运行的。
或者也可以拷贝原库文件,再用创建链接的方式创建一个。比如下面的指令会创建一个指向库文件so.5.13.2的链接so.5。
ln -s /opt/QT5.13.2/5.13.2/gcc_64/lib/libQt5XcbQpa.so.5.13.2 libQt5XcbQpa.so.5
当然,so.5.13.2拷贝到新机器上之后,指令中源文件的地址要适当改一下。指令运行完之后,在新机器的执行目录下,会同时存在so.5.13.2和so.5两个文件。
补充:出现以下报错的也同样的问题,上述解决思路可以解决
解决
经过上网查询,这个问题主要是platforms文件夹中libqxcb.so的依赖库没有拷贝导致的。可是如何拷贝依赖库,是个大问题!
在程序当前目录下输入ldd platforms/libqxcb.so后,提示/usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5 “not found”,去原linux电脑中,确实找到了libQt5XcbQpa.so.5文件,但把这个文件拷贝到release所在目录下并没有效果!
研究了一天,才明白libQt5XcbQpa.so.5文件是链接文件!使用ls -al可以找到链接文件对应的源文件!把源文件拷贝到release目录下,再新建一个相同名字的链接文件,才算完成了这个libQt5XcbQpa.so.5资源文件的打包!!
新建链接文件的命令:ln -s $PWD/libQt5XcbQpa.so.5.8.0 libQt5XcbQpa.so.5。
同样的,还有一个libQt5DBus.so.5的链接文件,也要通过拷贝真实文件(libQt5DBus.so.5.8.0)到打包目录,然后通过ln -s $PWD/libQt5DBus.so.5.8.0 libQt5DBus.so.5命令建立同名的链接文件。
“xcb” in “”的问题完美解决,程序正常启动运行了。
————————————————
单独说3条重要的指令:
1、在终端中输入export QT_DEBUG_PLUGINS=1指令,在运行QT程序时,可以打印详细的报错信息
2、在终端中输入export LD_LIBRARY_PATH=’/home/xujianjun/release’:$LD_LIBRARY_PATH指令,可以指定程序执行的库文件目录
3、sudo chmod -R 777 release 打开此文件夹下所有文件以及文件夹的可读,可写,可执行权限
最后1个问题:
如果换台电脑,程序无法加载显示背景图?
注意将/home/xujianjun/Qt5.13.0/5.13.0/gcc_64/plugins下的imageformats整个文件夹,拷贝到程序根目录下
备注:程序尽量发布在英文目录下