“项目错误:QT 中的未知模块:多媒体"使用新鲜的静态 Qt5.3.0 构建我的项目时 [英] "Project ERROR: Unknown module(s) in QT: multimedia" when building my project with fresh static Qt5.3.0

查看:102
本文介绍了“项目错误:QT 中的未知模块:多媒体"使用新鲜的静态 Qt5.3.0 构建我的项目时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have configured and built my own release version of Qt for gcc 64bit on linux, and with static linkage.

过程是这样的(来自 qt 附带的 README 文件):

The process goes like this (from the README file deliverd with qt):

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

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

When I use the resulting qmake on my previously working project, it quits with the message

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

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

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

My project file contains the following:

QT += core gui xml network widgets multimedia multimediawidgets svg

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

My question is thus, what is the correct way to compile qt statically while including all desired modules in the build?

谢谢!

推荐答案

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

It turns out that building qt statically was more difficult than I first expected (hoped?)

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

In this answer I will outline my journey to finally have a complete working statically linked qt that will compile properly with my project on Qt5/64bit/Linux.

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

First a list of hints that were crucial for my success:

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

  1. Make sure to have the 3rd party dependencies that qt require installed. The easiest way to arrange for this is to install the development packages using the package management in your Linux distribution. The more hardcore way is to actually download the sources and build them yourself, making sure to include the appropriate -L and -l options. For a complete list of dependencies, look at the official guide on how to build qt5 from git. It has instructions on exactly which packages are needed by each qt module, and how to install them for several popular distributions. Why? Some modules (such as qtmultimedia) will test the build environment for available dependencies, and will adapt to this. If you are missing some dependencies you will end up with a qtmultimedia module that does not support video or audio or both (missing pulse/alsa/gstreamer dev libs).

构建qt有两种基本方法.您可以构建qtin-tree"和out-of-tree".我发现out-of-tree"方法让你承担更多的工作,而最终它对我来说是最直观的.我在这个答案中继续采用这种方法.in-tree"意味着你依赖于你的源目录中已经建立的文件夹结构(阅读:很多你不容易掌握的东西).out-of-tree"意味着您创建一个构建目录并从那里开始构建过程.这也称为影子构建".我觉得这更直观的原因是,您可以查看 shadow 目录内部,以查看在每个步骤中制作/复制/更改了哪些文件,如果文件丢失,您立即知道出了什么问题.

There are two fundamental ways to build qt. You can build qt "in-tree" and "out-of-tree". I have found that the "out-of-tree" approach leaves more work on your shoulders while in the end it is the most intuitive for me. I have proceeded with this approach in this answer. "in-tree" means that you rely on the already established folder structure found in your source directory(read: lots of stuff you don't grasp easily). "out-of-tree" means that you make a build directory and start the build process from there. This is also referred to as "shadow build". The reason why I find this more intuitive is that you can look inside the shadow directory to see what files have been made/copied/changed at every step of the way, and if files are missing you know at once that something is wrong.

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

Some of the configure options will have adverse effects. For example the -fully-process option, while it promised to include everything, broke my build. Read the output of ./configure --help carefully and try to understand what each point actually means.

EDIT ADDED 2016-05-04: Qt build 实际上会生成一堆日志文件,您可以检查这些文件以获取有关模块丢失或无法构建的详细信息正如预期的那样.我在 在 docker 下构建 Qt 5.6.0 时提交了一个相关的错误时发现了这一点.

EDIT ADDED 2016-05-04: Qt build actually produces a bunch of log files that you can inspect to get good info about why modules are missing or why things don't build as expected. I discovered this while filing a somewhat related bug while building Qt 5.6.0 under docker.

您很可能最终会得到一个仅构建 qtbase 模块和其他模块(例如 qtmultimediaqtsvg)的配置 必须在之后构建.但是不要消失,这样做实际上比听起来更简单.

You will most likely end up with a configuration that builds only the qtbase module, and the rest of the modules such as qtmultimedia and qtsvg will have to be built after. But do not disappear, doing this is actually simpler than it sounds.

您决定构建单独模块的顺序很重要.如果您没有首先构建它们的依赖项,则某些模块将不会构建.例如 qtdeclarative 要求先构建 qtscript.

The order in which you decide to build the separate modules matters. Some modules will not build if you have not first built their dependancies. For example qtdeclarative requires qtscript to be built first.

我强烈建议您在构建 qt 时记录您的进度.我通过逐步改进一个 shell 脚本来做到这一点,该脚本将执行到这一点的所有步骤.我将在这篇博文中分享我的脚本,希望它可以作为帮助您快速启动和运行的指南.

I would strongly advice documenting your progress while building qt. I did this by incrementally improving a shell script that would perform all the steps that worked up this point. I will share my script in this post in the hope that it will be useful as a guide to get you up and running quickly.

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

Now with those general tips out of the way, here is my complete bash-script for downloading a version of qt5, configuring it and building it to taste:

这在 Ubuntu 12.04 x64 上运行正常,但是当我在 Debian 7.0 x64 上复制该过程时它失败并显示错误消息:相同格式:项目错误:QT 中的未知模块:快速svg 多媒体小部件多媒体".经过一些故障排除后,我发现通过连续两次运行配置和构建步骤而无需清理解决了这个问题.我知道这不是一个优雅的解决方案,但我有点希望一些 Qt5 官员/专业人士对此提出答案,而不是我试图通过反复试验找出问题.我在这里提交了一个关于 qt 的错误报告:https://bugreports.qt.io/浏览/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 以使其可执行.创建一个空目录并从那里运行脚本.

To use this script, put it in a new text file such as qt.sh and chmod +x qt.sh to make it executable. Make an empty dir and run the script from there.

完成后,生成的 qmake 将在 /qt/build//qtbase/bin 下.您应该能够像任何其他 qmake 一样使用它,从命令行、脚本或 QtCreator.示例:

After it is complete, the resulting qmake will be under <your dir>/qt/build/<version>/qtbase/bin. You should be able to use this like any other qmake, from commandline, script or QtCreator. Example:

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 文件并查看发生了什么.

If something goes wrong, you can now open the $LOG file using your favourite text editor and look at what happened.

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

And finally, to verify that your project was compiled with qt linked statically, you can run ldd my_binary and see that the list of dynamically linked libraries contains no mention of qt what-so-ever. WIN!

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

I don't know if this is the best way to do it, so if you know a better way, or have improvements, please do not hesitate to share!

这篇关于“项目错误:QT 中的未知模块:多媒体"使用新鲜的静态 Qt5.3.0 构建我的项目时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆