"项目错误:QT中的未知模块:多媒体"用新的静态Qt5.3.0构建我的项目

Len*_*and 5 qt static-libraries qt5

我已经在linux上为gcc 64bit配置并构建了我自己的Qt发行版,并且具有静态链接.

这个过程是这样的(从使用qt发送的README文件):

  1. 下载qt-everywhere-*源码tarball
  2. 将qt解压缩到"qtdir"文件夹中
  3. 在"qtdir"旁边制作一个新的dir"shadow"并进入它
  4. 运行"qtdir"/ qtbase/configure -prefix"qtdir"/ qtbase
  5. 运行make
  6. 等待qt构建完成.花了很短的时间.
  7. 使用生成的qmake构建我的项目

当我在之前工作的项目中使用生成的qmake时,它会退出并显示消息

"项目错误:QT中的未知模块:多媒体多媒体小部件

我的项目文件包含以下内容:

QT += core gui xml network widgets multimedia multimediawidgets svg
Run Code Online (Sandbox Code Playgroud)

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

谢谢!

Len*_*and 7

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

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

首先是一系列对我的成功至关重要的提示:

  1. 确保安装了qt require的第三方依赖项.安排此操作的最简单方法是使用Linux发行版中的软件包管理来安装开发软件包.更硬核的方法是实际下载源并自己构建它们,确保包含适当的-L和-l选项.有关依赖项的完整列表,请查看有关如何从git构建qt5的官方指南.它有关于每个qt模块究竟需要哪些软件包的说明,以及如何为几个流行的发行版安装它们.为什么?某些模块(例如qtmultimedia)将测试构建环境以获取可用的依赖项,并将适应这一点.如果您缺少某些依赖项,最终会得到一个qtmultimedia不支持视频或音频或两者兼有的模块(缺少pulse/alsa/gstreamer dev libs).

  2. 构建qt有两种基本方法.你可以构建qt"in-tree"和"out-of-tree".我发现"树外"方法会让你的肩膀上有更多的工作,而最终它对我来说是最直观的.我在这个答案中已经采用了这种方法."in-tree"意味着你依赖于源目录中已经建立的文件夹结构(阅读:许多你不容易掌握的东西)."out-of-tree"表示您创建一个构建目录并从那里开始构建过程.这也称为"阴影构建".我之所以发现这更直观,是因为你可以查看影子目录内部以查看在每一步中制作/复制/更改了哪些文件,如果缺少文件,则立即知道出现了问题.

  3. 某些配置选项会产生不利影响.例如,该-fully-process选项虽然承诺包含所有内容,但却破坏了我的构建../configure --help仔细阅读输出并尝试理解每个点的实际含义.

  4. 编辑增加2016-05-04: Qt构建实际上会生成一堆日志文件,您可以检查这些文件以获取有关模块缺失原因或为什么事情无法按预期构建的良好信息.在docker下构建Qt 5.6.0时,我发现了这个问题.

  5. 你很可能会结束与建立只有一个配置qtbase模块和模块等其他地区qtmultimedia,并qtsvg就必须修建的.但是不要消失,这样做实际上比听起来更简单.

  6. 您决定构建单独模块的顺序很重要.如果您尚未首先构建其依赖项,则某些模块将无法构建.例如,qtdeclarative需要qtscript首先构建.

  7. 我强烈建议在构建qt时记录你的进度.我通过逐步改进shell脚本来执行此操作,该脚本将执行此时所做的所有步骤.我将在这篇文章中分享我的脚本,希望它可以作为一个指导,让你快速启动和运行.

现在有了这些一般提示,这里是我完整的bash脚本,用于下载qt5版本,配置它并构建它以尝试:

编辑:这在Ubuntu 12.04 x64上运行正常,但是当我在Debian 7.0 x64上复制过程时,它失败并显示错误消息:格式相同:"项目错误:QT中的未知模块:快速svg multimediawidgets multimedia".经过一些故障排除后,我发现通过连续两次运行配置和构建步骤而不进行清理可以解决这个问题.我知道,这不是一个优雅的解决方案,但我有点希望一些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"
Run Code Online (Sandbox Code Playgroud)

要使用此脚本,请将其放在新的文本文件中qt.sh,chmod +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.
Run Code Online (Sandbox Code Playgroud)

如果出现问题,您现在可以使用您喜欢的文本编辑器打开$ LOG文件并查看发生的情况.

最后,为了验证你的项目是用静态链接的qt编译的,你可以运行ldd my_binary并看到动态链接库的列表中没有提到qt what-so-ever.赢得!

我不知道这是否是最佳方式,所以如果你知道更好的方法,或者有改进,请不要犹豫,分享!