我已经在Linux上为gcc 64位配置并构建了自己的Qt发行版,并带有静态链接。
该过程是这样的(从qt附带的README文件中):
当我在先前工作的项目上使用生成的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上的项目正确编译。
首先列出了对我的成功至关重要的提示:
qtmultimedia
)将测试构建环境中的可用依赖项,并将对此进行适应。如果缺少某些依赖项,您将得到一个不支持视频或音频或两者都不支持的qtmultimedia
模块(缺少pulse/alsa/gstreamer dev libs)。 -fully-process
选项虽然 promise 包括所有内容,但它破坏了我的构建。仔细阅读./configure --help
的输出,并尝试了解每个点的实际含义。 qtbase
模块的配置,而其余模块(例如qtmultimedia
和qtsvg
)将必须在此之后构建。但是请不要消失,这样做实际上比听起来容易。 qtdeclarative
需要首先构建qtscript
。 现在,这些一般性技巧已不复存在,这是我完整的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.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.
如果出现问题,您现在可以使用自己喜欢的文本编辑器打开$ 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/