qt打包发布问题 缺失qt动态库

ubuntu 升级QT版本后,在新机上发布QT程序报错:qt.qpa.plugin: Could not find the Qt platform plugin “xcb” in “”
原创啊拉丁的鱼 最后发布于2019-11-25 16:32:51 阅读数 511 收藏
展开
      本地原本使用的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两个文件。

补充:出现以下报错的也同样的问题,上述解决思路可以解决

 

 

 
————————————————
版权声明:本文为CSDN博主「啊拉丁的鱼」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/AAA123524457/article/details/103239301

 

linux下程序打包发布
原创HGT-teluoyi 最后发布于2018-10-30 19:05:53 阅读数 2361 收藏
展开
程序以test为例:

1. QtCreate使用Release版本编译

2. 从可运行程序的文件中拿出可执行文件,例:test

3. 终端下使用ldd命令查看需要的连接库,例:ldd test

4. 把ldd查询到的所有需要的库导出

这里提供一个脚本将ldd打印出来的依赖库复制到指定路径:

#!/bin/sh

 

exe="test" #发布的程序名称

des="./lib" #你的路径

 

deplist=$(ldd $exe | awk  '{if (match($3,"/")){ printf("%s "),$3 } }')

cp $deplist $des

 

5. 编写.sh文档 并将它放在与步骤4同一目录下(.sh文件命名必须与可执行文件名字一样例:可执行文件名 test, .sh 文件名为 test.sh)

.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 "$@"

 

6. 执行这个.sh文件:

可能因为不行执行需更改权限:

chmod +x test.sh
————————————————
版权声明:本文为CSDN博主「HGT-teluoyi」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u013305101/java/article/details/83547059

你可能感兴趣的:(qt打包发布问题 缺失qt动态库)