qt - 使用新鲜的静态Qt5.3.0构建我的项目时,使用"Project ERROR: Unknown module(s) in QT: multimedia"

标签 qt static-libraries qt5

我已经在Linux上为gcc 64位配置并构建了自己的Qt发行版,并带有静态链接。

该过程是这样的(从qt附带的README文件中):

  • 下载qt-everywhere- *源tarball
  • 将qt提取到文件夹“qtdir”中
  • 在“qtdir”旁边创建一个新的目录“shadow”并进入
  • 运行“qtdir”/qtbase/configure-前缀“qtdir”/qtbase
  • 运行make
  • 等待qt构建完成。花费令人惊讶的短时间。
  • 使用生成的qmake
  • 构建我的项目

    当我在先前工作的项目上使用生成的qmake时,它退出并显示以下消息:

    "Project ERROR: Unknown module(s) in QT: multimedia multimediawidgets



    我的项目文件包含以下内容:
    QT += core gui xml network widgets multimedia multimediawidgets svg
    

    因此,我的问题是,在构建中包括所有所需模块的同时静态编译qt的正确方法是什么?

    谢谢!

    最佳答案

    事实证明,静态构建qt比我最初预期的要困难得多(希望吗?)

    在这个答案中,我将概述我的旅程,最终将拥有一个完整的静态链接qt,该链接将与我在Qt5/64bit/Linux上的项目正确编译。

    首先列出了对我的成功至关重要的提示:

  • 确保已安装qt要求的第三方依赖关系。安排此操作最简单的方法是使用Linux发行版中的软件包管理来安装开发软件包。更严格的方法是实际下载源代码并自己构建它们,并确保包括适当的-L和-l选项。有关依赖项的完整列表,请参阅有关build qt5 from git的官方指南。它给出了有关每个qt模块确切需要哪些软件包以及如何为几种常用发行版安装它们的说明。为什么?一些模块(例如qtmultimedia)将测试构建环境中的可用依赖项,并将对此进行适应。如果缺少某些依赖项,您将得到一个不支持视频或音频或两者都不支持的qtmultimedia模块(缺少pulse/alsa/gstreamer dev libs)。
  • 有两种构建qt的基本方法。您可以构建“树内”和“树外”的qt。我发现“树外”方法使您的工作量更多,而最终这对我来说是最直观的。我已经在这个答案中使用了这种方法。 “在树中”意味着您依赖于在源目录中找到的已经建立的文件夹结构(阅读:很多您不容易掌握的内容)。 “树外”表示您创建了一个构建目录,并从此处开始构建过程。这也称为“阴影生成”。我之所以觉得这样更直观,是因为您可以查看影子目录内部的内容,以查看在每个步骤中都制作/复制/更改了哪些文件,如果文件丢失,您会立即知道出了点问题。
  • 一些配置选项会产生不利影响。例如,-fully-process选项虽然 promise 包括所有内容,但它破坏了我的构建。仔细阅读./configure --help的输出,并尝试了解每个点的实际含义。
  • 编辑添加于2016-05-04: Qt构建实际上会产生一堆日志文件,您可以检查这些日志文件,以获取有关为什么缺少模块或为什么构件无法按预期构建的良好信息。我在building Qt 5.6.0 under docker期间提交了一些相关的错误时发现了这一点。
  • 您很可能最终会获得仅构建qtbase模块的配置,而其余模块(例如qtmultimediaqtsvg)将必须在此之后构建。但是请不要消失,这样做实际上比听起来容易。
  • 决定构建独立模块的顺序很重要。如果您尚未先建立它们的依赖关系,则某些模块将不会建立。例如,qtdeclarative需要首先构建qtscript
  • 我强烈建议您在构建qt时记录您的进度。我是通过逐步改进将执行此步骤的所有步骤的Shell脚本来实现的。我将在本文中分享我的脚本,希望它对指导您快速起步和运行很有帮助。

  • 现在,这些一般性技巧已不复存在,这是我完整的bash脚本,用于下载qt5版本,对其进行配置并使其具有品味:

    编辑:在Ubuntu 12.04 x64上工作正常,但是当我在Debian 7.0 x64上复制该过程时,它失败并显示错误消息:格式相同:“项目错误:QT中的未知模块:快速svg multimediaswidgets多媒体”。经过一些故障排除后,我发现通过连续运行两次配置和构建步骤而无需清理即可解决此问题。我知道这不是一个很好的解决方案,但我有点希望一些Qt5官员/专业人士为此提供答案,而不是我尝试通过反复试验弄清楚问题。我已经在这里提交了有关qt的错误报告:https://bugreports.qt.io/browse/QTBUG-39733
    #!/bin/bash
    
    # Dependencies:
    sudo apt-get install build-essential perl python git "^libxcb.*" libx11-xcb-dev libglu1-mesa-dev libxrender-dev  libasound2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
    
    # Change this variable to suit your need
    VER="5.2.1"
    
    
    VER2="${VER%.*}"
    WSRC="http://download.qt-project.org/official_releases/qt/$VER2/$VER/single/qt-everywhere-opensource-src-$VER.tar.xz"
    
    # Current dir ( allows this script to be called from another dir)
    B=$(pwd)
    # Base folder for the whole operation
    Q="$B/qt"
    # The uncompressed source
    SRC="$Q/src/$VER"
    # The actual shadow dir
    O="$Q/build/$VER"
    # The tar.xz archive
    XZ="$Q/xz/qt-$VER.tar.xz"
    # Paralelle make, number of cores
    J=$(grep -c ^processor /proc/cpuinfo)
    # Build log file
    LOG="$O/log.txt"
    
    # My configuration options for qt change to your hearts content, but make sure to clean out your current build before using it.
    OPTS=""
    OPTS+=" -release"
    OPTS+=" -opensource"
    OPTS+=" -static" 
    OPTS+=" -confirm-license"
    #OPTS+=" -fully-process" #Breaks my build
    OPTS+=" -c++11"
    OPTS+=" -largefile" 
    #OPTS+=" -continue"
    OPTS+=" -silent"
    #OPTS+=" -optimized-qmake" 
    #OPTS+=" -reduce-relocations"
    OPTS+=" -qpa xcb"
    #OPTS+=" -declarative"
    OPTS+=" -opengl"
    #OPTS+=" -svg"
    OPTS+=" -qt-zlib" # ........... Use the zlib bundled with Qt.
    OPTS+=" -qt-libpng" # ......... Use the libpng bundled with Qt.
    OPTS+=" -qt-libjpeg" # ........ Use the libjpeg bundled with Qt.
    OPTS+=" -qt-freetype" # ........ Use the freetype bundled with Qt.
    OPTS+=" -qt-harfbuzz" # ........ Use the freetype bundled with Qt.
    OPTS+=" -qt-pcre" # ........... Use the PCRE library bundled with Qt.
    OPTS+=" -qt-xcb" # ............ Use xcb- libraries bundled with Qt.
    OPTS+=" -qt-xkbcommon" # ...... 
    OPTS+=" -no-gtkstyle"
    OPTS+=" -no-sql-db2" 
    OPTS+=" -no-sql-ibase" 
    OPTS+=" -no-sql-mysql" 
    OPTS+=" -no-sql-oci" 
    OPTS+=" -no-sql-odbc" 
    OPTS+=" -no-sql-psql" 
    OPTS+=" -no-sql-sqlite" 
    OPTS+=" -no-sql-sqlite2" 
    OPTS+=" -no-sql-tds"
    OPTS+=" -no-gif"
    OPTS+=" -no-nis"
    OPTS+=" -no-cups" 
    OPTS+=" -no-iconv"
    OPTS+=" -no-dbus"
    OPTS+=" -no-eglfs"
    OPTS+=" -no-directfb" 
    OPTS+=" -no-linuxfb"
    OPTS+=" -no-glib"
    OPTS+=" -no-kms"
    OPTS+=" -nomake examples" 
    #OPTS+=" -nomake demos" NOT AVAILABLE ANYMORE
    OPTS+=" -nomake tests"
    #OPTS+=" -no-openssl"
    
    # The modules that are relevant for me. Please observe that THE ORDER MATTERS! I would add one module at the time and see how it complains when you try to build it.
    MODS="qtx11extras qtimageformats qtscript qtquick1 qtdeclarative qtquickcontrols qtsvg qtmultimedia"
    
    # Just echo out the current state before starting the configuration and make
    echo "B: $B"
    echo "MODS: $MODS"
    echo "OPTS: $OPTS"
    echo "Q: $Q"
    echo "O: $O"
    echo "XZ: $XZ"
    echo "SRC: $SRC"
    echo "J: $J"
    echo "LOG: $LOG"
    
    # Create dirs
    mkdir -p "$Q"
    mkdir -p "$Q/xz"
    mkdir -p "$SRC"
    mkdir -p "$O"
    # Start log
    date > $LOG
    # Download source archive
    [ ! -f $XZ ] && wget "$WSRC" -c -O "$XZ"
    # Unpack source archive
    [ ! -x $SRC/configure ] && tar pxf "$XZ" --strip=1 -C "$SRC" "qt-everywhere-opensource-src-$VER" 
    # Configure qt build
    cd "$O"
    MAKEFLAGS=-j$J "$SRC/configure" $OPTS
    
    # Build qtbase with new config (results in the basic qt libs plus a new qmake that you can use for building the rest of the modules and your own projects).
    # TIP: Don't put make all here
    make -j$J >> $LOG
    
    #build your modules with the new qmake, keeping the resulting static libs in each module's shadow build folder where they will be located by qmke during compilation of your projects
    for M in $MODS
    do
        echo "----------------------------------------- MODULE: $M"
        echo "----------------------------------------- MODULE: $M" >> $LOG
        # Make module dir
        D=$O/$M
        mkdir -p $D
        cd $D
        # Use new qmake to create module makefile
        $O/qtbase/bin/qmake $SRC/$M/
        # Build module
        make -j$J >> $LOG
    done
    
    echo "DONE"
    

    要使用此脚本,请将其放在新的文本文件(例如qt.shchmod +x qt.sh)中以使其可执行。制作一个空目录,然后从那里运行脚本。

    完成后,生成的qmake将在<your dir>/qt/build/<version>/qtbase/bin下。您应该能够从命令行,脚本或QtCreator像其他任何qmake一样使用它。例子:
    cd ~ # Go to home dir
    mkdir lol #Make a temporary dir
    cd lol # Go into the temporary dir
    <full path to script> # Run the script from this temporary dir
    # [ ... wait for script to download, configure and build qt]
    cd qt/build/<version> # Go into the output directory
    ls # List all module folders
    ls -hal qtbase/bin
    /qmake # Show details on new qmake binary which should be configured to build your projects with static qt linkage by linking to module libraries from this dir.
    

    如果出现问题,您现在可以使用自己喜欢的文本编辑器打开$ LOG文件,然后查看发生了什么。

    最后,要验证您的项目是使用静态链接的qt编译的,可以运行ldd my_binary并查看动态链接库的列表中没有提及qt。赢!

    我不知道这是否是最好的方法,因此,如果您知道更好的方法或有所改进,请随时分享!

    关于qt - 使用新鲜的静态Qt5.3.0构建我的项目时,使用"Project ERROR: Unknown module(s) in QT: multimedia",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24275551/

    相关文章:

    c++ - 使用 native C++ Qt 比 PyQt 有什么优势

    c++ - QSqlTableModel::setData() 对于 Qt::EditMode 也返回 false

    ios - 静态库 - 复制文件目标

    ios - 在构建时更改子程序名称以避免 Xcode 中的冲突

    c++ - 从另一个类调用 QQmlApplicationEngine 时的 TableView 和 QAbstracTableModel

    c++ - QAbstractSpinBox - indexChanged 信号

    linux - 为什么Qt平台插件 "xcb"找到了却无法加载?

    qt - 在 Qt 中 QTextCodec::codecForName ("UTF-16") 和 codecForName ("UTF-32") 如何决定使用的字节顺序?

    qt - 如何使用静态构建的 Qt 解决此 'no service found for - “org.qt-project.qt.mediaplayer” ' 错误?

    ios - 为 iOS 构建 Qt