简体   繁体   English

在Ubuntu 12.04上构建静态Qt 4.8.1

[英]Static Qt 4.8.1 Build on Ubuntu 12.04

I am attempting to build an almost static application because of portability concerns. 由于可移植性问题,我试图构建一个几乎静态的应用程序。 I hope to be able to run the executable on several 64 bit linux distributions. 我希望能够在几个64位linux发行版上运行该可执行文件。 I have been successful at statically linking Qt and building with statically linked libstdc++ and libgcc. 我已经成功地静态链接了Qt并使用静态链接的libstdc ++和libgcc进行了构建。

However, I have some 3rd party library concerns. 但是,我有一些第三方图书馆的问题。 I built Qt with -qt-zlib, but my end application is still dynamically linked with the system zlib. 我使用-qt-zlib构建了Qt,但最终应用程序仍与系统zlib动态链接。 Specifically I configured with: 我特别配置了:

./configure -static -nomake demos -nomake examples -nomake tools -release -no-webkit -qt-zlib -no-gif -qt-libtiff -qt-libpng -qt-libmng -qt-libjpe

I removed all references linking to zlib in the application, assuming that the application would be able to link to the Qt's statically built zlib. 假定应用程序能够链接到Qt的静态构建的zlib,我删除了该应用程序中所有链接到zlib的引用。 It almost appears to me that Qt is ignoring the -qt-zlib flag, and using the system library, which then my application also uses. 在我看来,Qt几乎忽略了-qt-zlib标志,而是使用系统库,然后我的应用程序也使用该系统库。

Furthermore, I had to install the libfontconfig-dev package so the font after building from source would not be horrific, but now Qt is also dynamically linking to it. 此外,我必须安装libfontconfig-dev软件包,这样从源构建后的字体就不会太恐怖了,但是现在Qt也可以动态链接到它了。 There is a static library for libfontconfig that I tried to link to, as you can see, but because Qt is already linked to libfontconfig, the linker ignores it. 如您所见,我尝试链接到libfontconfig的静态库,但是因为Qt已经链接到libfontconfig,所以链接程序会忽略它。 Is there a way during the Qt build of being able to specify not to dynamically link to 3rd party libraries? 在Qt构建过程中,有没有一种方法可以指定不动态链接到第三方库?

I do not want any of Qt's dependencies to be statically linked, if possible. 我不希望Qt的任何依赖项都被静态链接。 Right now I believe the application will work on at least Ubuntu 12.04, but other distributions very well may place some of the libraries in different places. 现在,我相信该应用程序至少可以在Ubuntu 12.04上运行,但是其他发行版也可以将某些库放在不同的位置。

Snippet from my .pro file: 我的.pro文件中的代码段:

QT += core \
      gui \
      opengl
QMAKE_CXXFLAGS += -fpermissive
QMAKE_LFLAGS += -static-libgcc -static-libstdc++
CONFIG += static
TEMPLATE = app
LIBS += /usr/local/lib/libboost_thread.a \
        /usr/local/lib/libboost_program_options.a \
        /usr/lib/x86_64-linux-gnu/libfontconfig.a \
        /usr/lib/x86_64-linux-gnu/libGLU.a

Output from ldd: ldd的输出:

linux-vdso.so.1 =>  (0x00007fff992b4000)
libSM.so.6 => /usr/lib/x86_64-linux-gnu/libSM.so.6 (0x00007f195ccbc000)
libICE.so.6 => /usr/lib/x86_64-linux-gnu/libICE.so.6 (0x00007f195caa2000)
**libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f195c86b000)**
libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f195c5cf000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f195c3be000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f195c089000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f195be85000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f195bc7d000)
**libGL.so.1 => /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 (0x00007f195ba1c000)**
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f195b7ff000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f195b505000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f195b147000)
/lib64/ld-linux-x86-64.so.2 (0x00007f195ced9000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f195af42000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f195ad18000)
**libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f195ab00000)**
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f195a8e2000)
libglapi.so.0 => /usr/lib/x86_64-linux-gnu/libglapi.so.0 (0x00007f195a6bd000)
libXdamage.so.1 => /usr/lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007f195a4b9000)
libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f195a2b3000)
libX11-xcb.so.1 => /usr/lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007f195a0b1000)
libxcb-glx.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-glx.so.0 (0x00007f1959e99000)
libXxf86vm.so.1 => /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007f1959c94000)
libdrm.so.2 => /usr/lib/x86_64-linux-gnu/libdrm.so.2 (0x00007f1959a89000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f1959885000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f195967f000)

Update: 更新:

I have since given up on this task as it does not seem doable. 此后,我放弃了这项任务,因为它似乎并不可行。 Since the developer has decided it would be okay to release the source, I will just port it with the standard ./configure, make, and make install. 由于开发人员已经决定可以发布源代码,因此我将使用标准的./configure、make和make install进行移植。

Even if I was able to link these libraries statically, libc was of a different version from even Ubuntu 11. So far as I know, libc cannot be statically linked. 即使我能够静态链接这些库,libc的版本也不同于Ubuntu11。据我所知,libc不能静态链接。 It appears the best option is to build a package with GNU's auto tools, but even that is a painful task. 看来最好的选择是使用GNU的自动工具构建一个程序包,但是即使那样也很痛苦。

Any hints or tips on how to go about using GNU's tools to create the ./configure script for a Qt project? 关于如何使用GNU工具为Qt项目创建./configure脚本的任何提示或技巧?

Building a completely static executable that is portable is not easily done. 构建一个可移植的完全静态的可执行文件并不容易。 There are a lot of technical concerns at why doing this is not really feasible, as I have learned. 据我了解,为什么这样做实际上并不可行,存在很多技术问题。 libc cannot be statically linked, so you must compile with an older version of libc for compatibility concerns. libc不能静态链接,因此出于兼容性方面的考虑,必须使用旧版本的libc进行编译。

The best solution for portability on linux platforms is releasing the source and using GNU's Autotools to build a ./configure script. 在Linux平台上实现可移植性的最佳解决方案是发布源代码并使用GNU的Autotools构建./configure脚本。 However, that task is not easily done with Qt projects. 但是,使用Qt项目很难完成该任务。

Ultimately, I resorted to releasing the source with a basic installation script that will check that Qt is installed on the machine and use qmake to build the project. 最终,我诉诸于使用基本安装脚本发布源代码,该脚本将检查计算机上是否安装了Qt并使用qmake来构建项目。 It's not a great solution, but it works. 这不是一个很好的解决方案,但可以。

If you are not willing to release the source, build a semi-statically (with Qt and possibly a few other libraries) linked executable and an installer that verifies the libraries are in the correct locations and installs them if necessary. 如果您不愿意发布源代码,请构建一个半静态(使用Qt以及可能还有其他一些库)链接的可执行文件,并安装一个安装程序以验证库是否位于正确的位置,并在必要时进行安装。

If I can guess .. 如果我能猜到..

Few time ago I was made a statically linked application in some Linux-based OS and i`ve had to include ALL static libraries, I wanna use and 3party too. 不久前,我在一些基于Linux的操作系统中成为一个静态链接的应用程序,我不得不包含所有静态库,我也想使用3party。 But with Qt modules it was an unclearly behavior .. for example for me: qico module I wanted will be included statically only with such constructions: 但是对于Qt模块来说,这是一个不清楚的行为..例如,对于我来说:我想要的qico模块将仅静态包含在以下结构中:

in .pro file: 在.pro文件中:

QTPLUGIN += qico
DEFINES += STATIC

in main.cpp: 在main.cpp中:

#ifdef STATIC
#include <QtPlugin>
Q_IMPORT_PLUGIN(qico)
#endif

Possibly it will help. 可能会有所帮助。

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

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