简体   繁体   English

使用静态Qt构建在Linux上部署Qt5应用程序

[英]Deploying Qt5 application on Linux using static Qt build

I have built and installed a static build of Qt5.11 on ubuntu using the commands below: 我已经使用以下命令在ubuntu上构建并安装了Qt5.11的静态版本:

make distclean; ./configure 
-static -release -ltcg -optimize-size -no-pch -prefix 
"/opt/qt/511-static-release" -skip webengine -nomake tools 
-nomake tests -nomake examples; make -j 8; make install;

The build finishes successfully. 构建成功完成。

I then try and link my project against this build but it fails. 然后,我尝试将我的项目与此版本链接,但失败。 Here are the last few lines of output: 这是输出的最后几行:

Compilation output (Qt-Creator) 编译输出(Qt-Creator)

...

../src/config/config_dialog.h -o moc_config_dialog.cpp
g++ -c -pipe -std=c++11 -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC - 
DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB 
-DQT_CORE_LIB -I../../my-gui-qt -I. -I../src/view/ -I./model - 
I/opt/qt/511-static-release/include -I/opt/qt/511-static- 
release/include/QtWidgets -I/opt/qt/511-static-release/include/QtGui - 
I/opt/qt/511-static-release/include/QtNetwork -I/opt/qt/511-static- 
release/include/QtCore -I. -isystem /usr/include/libdrm -I. - 
I/opt/qt/511-static-release/mkspecs/linux-g++ -o moc_config_dialog.o 
moc_config_dialog.cpp

Linker output 链接器输出

 g++ -Wl,-Bdynamic -lGL -static -fPIC -o my-gui-qt main.o 
 mainwindow.o task_status_delegate.o my-gui-qt_plugin_import.o  
 qrc_resources.o moc_mainwindow.o moc_task_table_view.o 
 moc_task_table_model.o moc_config_dialog.o 
 -L/opt/qt/511-static-release/lib -lQt5OpenGL -L/usr/lib/x86_64-linux-
 gnu -L/opt/qt/511-static-release/plugins/platforms 
 -lqxcb -L/opt/qt/511-static--release/plugins/xcbglintegrations 
 -lqxcb-glx-integration -lQt5XcbQpa -lQt5ServiceSupport 
 -lQt5ThemeSupport -lQt5EventDispatcherSupport 
 -lQt5FontDatabaseSupport -lfontconfig -lfreetype -lQt5GlxSupport - 
 lXext -lQt5EdidSupport -lxcb-glx -lX11-xcb -lX11 -lXi -lSM -lICE - 
 lXrender -lxcb-static -lxcb -L/opt/qt/511-static- 
 release/plugins/imageformats -lqgif -lqicns -lqico -lqjpeg -lqtga - 
 lqtiff -lqwbmp -lqwebp -L/opt/qt/511-static-release/plugins/bearer - 
 lqconnmanbearer -lqgenericbearer -lqnmbearer -lQt5DBus -lQt5Widgets - 
 lQt5Gui -lpng12 -lqtharfbuzz -lQt5Network -lQt5Core -lm -lz -licui18n 
 -licuuc -licudata -lqtpcre2 -ldl -lgthread-2.0 -lglib-2.0 -lGL - 
 lpthread 

Linker warnings 链接器警告

../../include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:163:46: warning: type 'struct Function' violates one definition rule [-Wodr] .moc/qcolordialog.moc:111:57: note: a different type is defined in another translation unit ../../include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:163:46:警告:类型'struct Function'违反了一个定义规则[-Wodr] .moc / qcolordialog。 moc:111:57:注意:另一个翻译单元中定义了其他类型

dialogs/qcolordialog.cpp:1738:41: note: the first difference of corresponding definitions is field '__pfn' dialogs / qcolordialog.cpp:1738:41:注意:相应定义的第一个区别是字段'__pfn'

.moc/qcolordialog.moc:111:56: note: a field of same name but different type is defined in another translation unit lto1: note: type mismatch in parameter 1 dialogs/qcolordialog.cpp:179:7: note: type 'struct QWellArray' defined in anonymous namespace can not match type 'struct QWellArray' .moc / qcolordialog.moc:111:56:注意:在另一个翻译单元lto1中定义了一个名称相同但类型不同的字段:注意:参数1对话框中的类型不匹配/qcolordialog.cpp:179:7:注意:输入'匿名命名空间中定义的struct QWellArray'与类型'struct QWellArray'不匹配

dialogs/qcolordialog.cpp:180:1: note: the incompatible type defined in anonymous namespace in another translation unit qicohandler.cpp:95:3: warning: type 'struct BMP_INFOHDR' violates one definition rule [-Wodr] dialogs / qcolordialog.cpp:180:1:注意:在另一个翻译单元qicohandler.cpp:95:3中的匿名名称空间中定义的不兼容类型:警告:类型'struct BMP_INFOHDR'违反了一个定义规则[-Wodr]

... and some more similar warnings.. ...以及其他一些类似的警告。

The link does complete and generate the executable but it is not run-able. 链接确实完成并生成可执行文件,但它不可运行。 I can see the file is there with: 我可以看到文件在那里:

$ file my-gui-qt

$ my-gui-qt: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), 
dynamically linked, interpreter /lib/ld64.so.1, for GNU/Linux 2.6.32, 
BuildID[sha1]=0e22025dfc5f4bf4dbba598a6f692607303b68c, not stripped

But trying to run it gives the error: 但是尝试运行它会出现错误:

me@me-Inspiron-15-7000-Gaming:~/code/my-gui-qt/build-static$ ./my-gui- 
qt 
bash: ./my-gui-qt: No such file or directory

EDIT: I was able to reproduce this problem with the same static build of Qt 5.11 and a trivial (tiny) Qt application using the same libs. 编辑:我能够使用相同的Qt 5.11静态构建和使用相同库的琐碎(小巧)Qt应用程序重现此问题。 The application compiles and runs fine until I add the same QMAKE flags as for the my-gui-qt application above: 该应用程序将编译并正常运行,直到添加与上述my-gui-qt应用程序相同的QMAKE标志:

QMAKE_LFLAGS += -Wl,-Bdynamic -lGL -static

Reason being that a different interpreter is linked in to the exe: 原因是将不同的解释器链接到exe:

So without the QMAKE_LFLAGS above 所以没有上面的QMAKE_LFLAGS

$file TestProject*

Gives: 得到:

TestProject: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), 
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for 
GNU/Linux 2.6.32, 
BuildID[sha1]=993c09e6977c18772569a5a6ecb452c03a884f2d, not stripped

And runs fine. 并运行良好。 However with the flags it gives: 但是带有标志它给出:

TestProject: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), 
dynamically linked, interpreter /lib/ld64.so.1, for GNU/Linux 2.6.32, 
BuildID[sha1]=29674cc4997c91b45f9c87bc53ee858b12639e3b, not stripped

And does not run (bash: : No such file or directory). 并且不运行(bash ::无此类文件或目录)。 Seems like setting the -Bdynamic flag will make gcc fallback to the generic Unix gcc interpreter /lib/lib64.so.1 which is not present in Ubuntu16.04. 似乎设置-Bdynamic标志将使gcc回退到Ubuntu16.04中不存在的通用Unix gcc解释器/lib/lib64.so.1。 Not sure how to fix this though? 不确定如何解决此问题? Have tried -Wl,--dynamic-linker=/lib/ld-lsb.so.2 without success.. 尝试-Wl,-dynamic-linker = / lib / ld-lsb.so.2没有成功..

So it turn out this problem was one that has been answered before, I just couldn't see it. 因此事实证明,这个问题是以前已经解决的,我只是看不到它。

When linking a Qt application against a static version of Qt but leaving some components (libGL.so) to be dynamically linked (ie QMAKE_LFLAGS += -Wl,-Bdynamic,- -lGL -static) the ELF interpreter may resolve to its default value (since the command above overrides the specific interpreter path), so to restore it you should specify it again (as many others have said) with something like this : 当将Qt应用程序链接到静态版本的Qt时,但某些组件(libGL.so)可以动态链接(即QMAKE_LFLAGS + = -Wl,-Bdynamic,--lGL -static),则ELF解释器可以解析为其默认值(由于上面的命令将覆盖特定的解释器路径),因此要恢复该路径,您应再次指定它(如许多其他人所说的那样),如下所示:

QMAKE_LFLAGS += -Wl,-dynamic-linker=/lib64/ld-linux-x86-64.so.2  

Application now runs fine. 应用程序现在可以正常运行。 Multiple definition warnings remains when using the combination of these flags (even for a trivial Qt application). 当使用这些标志的组合时,仍然会保留多个定义警告(即使对于琐碎的Qt应用程序)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM