温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Linux怎么编译qt

发布时间:2022-01-26 17:38:31 来源:亿速云 阅读:148 作者:iii 栏目:开发技术

这篇文章主要介绍了Linux怎么编译qt的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Linux怎么编译qt文章都会有所收获,下面我们一起来看看吧。

Linux怎么编译qt

首先下载源码包qt-everywhere-opensource-src-5.6.0.7z 然后解压

 7z x -o/home/o/qt-src/qt-opensource-src-5.6.0 qt-everywhere-opensource-src-5.6.0.7z
 
 cd /home/o/qt-src/qt-opensource-src-5.6.0

我这里解压到/home/o/qt-src/qt-opensource-src-5.6.0中,解压后进入这个目录。

configure生成makefile

先使用./configure --help来看看都有哪些参数,这里就不贴命令输出结果了,直接把选项都翻译出来

安装选项

选项作用
-prefix 指定部署目录(默认 /usr/local/Qt-5.6.0)
-extprefix 安装目录(默认 SYSROOT/PREFIX)
-hostprefix [dir]运行在这个主机上的构建工具的安装目录,如果不给定,使用当前目录. (默认 EXTPREFIX)

你可以用这些来改变安装的布局。请注意,所有目录除sysconfdir外,其他的应位于-prefix/ hostprefix下

选项作用
-bindir 用户可执行文件将安装到这个目录(默认 PREFIX/bin)
-headerdir 头文件安装目录(默认 PREFIX/include)
-libdir 库文件安装目录(默认 PREFIX/lib)
-archdatadir QT相关的数据将被安装到(默认 PREFIX)
-plugindir 插件安装目录(默认 ARCHDATADIR/plugins)
-libexecdir 程序的可执行文件安装目录(默认 ARCHDATADIR/libexec, ARCHDATADIR/bin for MinGW)
-importdir 导入QML1安装目录(默认 ARCHDATADIR/imports)
-qmldir 导入QML2安装目录(默认 ARCHDATADIR/qml)
-datadir QT独立的数据安装目录(default PREFIX)
-docdir 文档安装目录(default DATADIR/doc)
-translationdir Qt程序的翻译数据安装目录(default DATADIR/translations)
-sysconfdir 设置使用QT程序的搜寻目录(default PREFIX/etc/xdg)
-examplesdir 示例文件安装目录(default PREFIX/examples)
-testsdir 测试文件安装目录(default PREFIX/tests)
-hostbindir 主机可执行文件安装目录(default HOSTPREFIX/bin)
-hostlibdir 主机库文件安装目录(default HOSTPREFIX/lib)
-hostdatadir qmake使用数据安装目录(default HOSTPREFIX)

Configure选项

下表中第一列中的*表示默认并可行的。+表示默认,但需要进行评估(检测),评估通过才可接受。


选项作用
*-release编译和链接Qt的release版本

-debug编译和链接debug版本

-debug-and-release编译和链接release和debug两个版本(仅MAC)

-force-debug-info为release构建创建符号链接

-developer-buildQt开发者编译和链接选项(包括自动测试/输出)
*-no-optimized-tools即使在调试版本中,也不构建优化的主机工具

-optimized-tools构建优化的主机工具,即使在调试版本

-opensource编译和链接Qt开源版本

-commercial编译和链接的Qt商业版

-confirm-license自动确认许可证(使用开源或是商业)

-c++std 编译QT使用的C++标准 (c++98, c++11, c++14, c++1z) 默认: 最高支持版本
*-shared创建并使用Qt共享库.

-static创建并使用QT静态库

-no-largefile禁用大文件支持
+-largefile启用QT访问大于4 GB的文件功能

-no-accessibility不编译的可访问性支持 禁用访问不推荐,它将破坏QStyle并且可能影响QT构建  这个选项启用将创建一个源不兼容版本的QT,这是不支持
+-accessibility编译访问支持.

-no-sql-完全禁用SQL  .

-qt-sql-在 Qt SQL 模块启用SQL ,默认是不启用的.

-plugin-sql-启用SQL作为一个插件在运行时链接  的可能值为:  [ db2 ibase mysql oci odbc psql sqlite sqlite2 tds ]

-system-sqlite利用操作系统SQLite

-no-qml-debug不构建在QML调试支持
+-qml-debug构建QML调试支持

-platform target构建的目标操作系统和编译器(默认检测主机系统) 读readme文件获取支持的操作系统和编译器列表

-no-sse2编译不要使用SSE2指令

-no-sse3编译不要使用SSE3指令

-no-ssse3编译不要使用SSSE3指令

-no-sse4.1编译不要使用SSE4.1指令

-no-sse4.2编译不要使用SSE4.2指令

-no-avx编译不要使用AVX指令

-no-avx2编译不要使用AVX2指令

-no-mips_dsp编译不要使用MIPS DSP指令

-no-mips_dspr2编译不要使用MIPS DSP Rev2指令

-qtnamespace 把所有的Qt库代码放入namespace{...}

-qtlibinfix 重命名索引libQt*.so为libQt*.so

-testcocoonInstrument Qt with the TestCocoon code coverage tool.

-gcovInstrument Qt with the GCov code coverage tool.

-D 显示的添加一个宏定义到预处理器

-I 显示的添加一个包含路径

-L 显示添加一个库路径
+-pkg-config使用pkg-config检测包括库路径。默认情况下,配置决定是否使用pkg-config或不具有启发式如检查环境变量。

-no-pkg-config禁用pkg-config支持

-force-pkg-config强制使用pkg-config (跳过pkg-config可用性启发式检测).

-help, -h显示帮助信息.

第三方库:


选项作用

-qt-zlib使用QT自带zlib库
+-system-zlib使用操作系统自带的zlib库。 http://www.gzip.org/zlib

-no-mtdev不要编译mtdev支持  mtdev包含了应用程序对多点触摸协议的支持
+-mtdev启用mtdev的支持.
+-no-journald不要把日志输出到journald.  Journald是为Linux服务器打造的新系统日志方式

-journald日志输出到journald
+-no-syslog不要输出日志到syslog.

-syslog输出日志到syslog.

-no-gif不要编译GIF读取支持

-no-libpng不要编译PNG支持

-qt-libpng使用Qt自带的libpng
+-system-libpng使用操作系统自带的libpng  http://www.libpng.org/pub/png

-no-libjpeg不要编译JPEG支持.

-qt-libjpeg使用QT自带的libjpeg.
+-system-libjpeg使用系统自带的 libjpeg  http://www.ijg.org

-no-freetype不要编译Freetype2的支持.

-qt-freetype使用QT自带的libfreetype.
+-system-freetype使用系统自带的libfreetype(假如存在) (启用,如果-fontconfig选项开启).  http://www.freetype.org

-no-harfbuzz不要编译HarfBuzz-NG 支持.
*-qt-harfbuzz使用QT自带的HarfBuzz-NG 去进行文本构形. 仍然可以通过设置QT_HARFBUZZ 环境变量到”old”来禁用.

-system-harfbuzz使用系统自带的HarfBuzz-NG区进行文本构形.仍然可以通过设置QT_HARFBUZZ 环境变量到”old”来禁用  http://www.harfbuzz.org

-no-openssl不要编译OpenSSL的支持

-openssl启用运行时OpenSSL支持.

-openssl-linked启用并链接OpenSSL支持

-no-libproxy不要编译libproxy的支持
+-libproxy使用操作系统自带的libproxy.

-qt-pcre使用QT自带的PCRE library.
+-system-pcre使用操作系统自带的PCRE library

-qt-xcb使用QT自带的xcb-libraries. (libxcb.so将仍然使用操作系统自带的).
+-system-xcb使用操作吸引自带的xcb- libraries .

-xkb-config-root设置默认的XKB config root. 这个选项仅与-qt-xkbcommon-x11一起使用.

-qt-xkbcommon-x11在构建xcb中使用QT自带的xkbcommon library .
+-system-xkbcommon-x11在构建xcb中使用操作系统自带的 xkbcommon library.

-no-xkbcommon-evdev当编译libinput支持时,不使用X-less xkbcommon.
*-xkbcommon-evdev当编译libinput支持时,使用X-less xkbcommon.

-no-xinput2不要编译XInput2的支持.
*-xinput2编译XInput2支持.

-no-xcb-xlib不要编译Xcb-Xlib支持.
*-xcb-xlib编译 Xcb-Xlib支持.

-no-glib不要编译 Glib 支持.
+-glib编译 Glib 支持.

-no-pulseaudio不要编译PulseAudio 支持.
+-pulseaudio编译 PulseAudio 支持.

-no-alsa不要编译 ALSA 支持.
+-alsa编译 ALSA 支持.

-no-gtkstyle不要编译GTK theme 支持.
+-gtkstyle编译 GTK theme 支持.

附加选项:


选项作用

-make 在make时添加要构建的组件. (默认为:libs tools examples

-nomake 在构建时排除组件

-skip 排除整个模块的建立

-no-compile-examples仅安装examples的源码,不要编译它.

-no-gui不要构建Qt GUI模块和依赖.
+-gui构建Qt GUI 模块和依赖.

-no-widgets不要构建Qt Widgets 模块和依赖.
+-widgets构建 Qt Widgets模块和依赖

-R 显示添加一个运行时库的路径去构建Qt libraries.

-l 显示添加一个library.

-no-rpath不使用库安装路径作为一个运行时库路径  在苹果的平台上,这意味着使用绝对安装名称(基于在libdir)动态库和框架。
+-rpath链接 Qt 库和可执行文件使用库安装路径作为运行时库路径。相当于-R install_libpath

-continue如果发生错误,尽量继续。

-verbose, -v打印每个步骤的配置过程的详细的信息。

-silent减少生成输出,这样可以更容易看到警告和错误。

-no-nis不要编译NIS 支持.
*-nis编译 NIS 支持.

-no-cups不要编译CUPS支持.
*-cups编译CUPS支持. 要求 cups/cups.h 和libcups.so.2.

-no-iconv不编译对 iconv(3) 的支持。
*-iconv编译对 iconv(3) 的支持。

-no-evdev不编译对 evdev 的支持。
*-evdev编译对 evdev 的支持。

-no-tslib不编译对 tslib 的支持  tslib是对触屏的支持
*-tslib编译对 tslib 的支持.

-no-icu不编译对 ICU libraries 的支持.  这是IBM发布的字符集编码转换库
+-icu编译对 ICU libraries 的支持.

-no-fontconfig不编译系统中的FontConfig支持
+-fontconfig编译系统中的FontConfig支持

-no-strip不对二进制文件和库的使用strip去除不需要的符号.
*-strip在安装时对二进制文件和库的使用strip去除不需要的符号
*-no-pch不使用预编译的头支持.

-pch使用预编译的头支持.
*-no-ltcg不使用链接时代码生成

-ltcg使用链接时代码生成.

-no-dbus不要编译Qt D-Bus 模块.
+-dbus-linked编译Qt D-Bus模块并链接到libdbus-1.

-dbus-runtime编译Qt D-Bus模块并动态加载libdbus-1.

-reduce-relocations减少通过额外的链接器优化库的重加载  (仅qt/X11 和Qt/linux嵌入式 ;实验性的;需要 GNU ld > = 2.18)

-no-use-gold-linker不要使用GNU gold linker进行链接.
+-use-gold-linker使用GNU gold linker进行链接.

-force-asserts强制启用Q_ASSERT,即使在release构建中.

-sanitize [address/thread/memory/undefined]启用指定编译器的sanitizer.

-device 跨平台编译设备 (试验性)

-device-option 添加device mkspec的device选项 (试验性)
*-no-separate-debug-info不将调试信息存储在一个单独的文件

-separate-debug-info将调试信息到一个单独的文件

-no-xcb不要编译Xcb (X protocol C-language Binding) 支持.
*-xcb编译 Xcb 支持.

-no-eglfs不要编译EGLFS (EGL Full Screen/Single Surface) 支持.
*-eglfs编译 EGLFS 支持.

-no-kms不要编译KMS的后端.
*-kms编译 KMS的后端.

-no-gbm不要编译 GBM 的后端.
*-gbm编译 GBM的后端.

-no-directfb不要编译 DirectFB 支持.
*-directfb编译 DirectFB 支持.

-no-linuxfb不要编译Linux Framebuffer 支持.
*-linuxfb编译 Linux Framebuffer 支持.
*-no-mirclient不要编译 Mir client 支持.

-mirclient编译 Mir client 支持.

-qpa 设置默认的QPA 平台 (示例 xcb, cocoa, windows).

-xplatform target指定目标平台(在跨平台编译时)

-sysroot 设置为目标编译器和 qmake 的 sysroot 并且也设置 pkg-confing路径.

-no-gcc-sysroot当使用-sysroot时, 它禁用将–sysroot传递到编译器

-no-feature-中的不编译.

-feature-编译中的.  可用的功能介绍在src/corelib/global/qfeatures.txt

-qconfig local使用src/corelib/global/qconfig-local.h ,而不是默认的(全部).

-qreal [double/float]为qreal指定类型.默认值是double。请注意,更改此标志影响二进制兼容性。

-no-opengl禁用OpenGL支持.

-opengl 启用 OpenGL 支持. 不带参数时,这将会尝试自动检测的 OpenGL ES 2.0 和更高版本,或常规的桌面版OpenGL.  使用 es2 的将替代自动检测

-no-libinput禁用libinput支持.
*-libinput启用libinput 支持.

-no-gstreamer禁用GStreamer支持.
+-gstreamer 启用 GStreamer 支持。 不带参数,这将会尝试自动检测 GStreamer 0.10 和 1.0。GStreamer 1.0 是默认使用的可用时。使用 0.10 或 1.0 来覆盖自动检测。
*-no-system-proxies默认情况下,不使用系统网络代理

-system-proxies默认情况下,使用系统网络代理

-no-warnings-are-errorsMake 时把warnings当做正常

-warnings-are-errorsMake时把warnings 当做错误 (如果启用了-developer-build)

QNX/Blackberry 选项:

选项作用
-no-slog2不编译 slog2 的支持
-slog2编译 slog2 的支持
-no-pps不编译 pps 的支持
-pps编译 pps 的支持
-no-imf不编译 imf 的支持
-imf编译 imf 的支持
-no-lgmon不编译 lgmon 的支持
-lgmon编译 lgmon 的支持

Android 选项:


选项作用

-android-sdk pathAndroid SDK 根目录   (默认 $ANDROID_SDK_ROOT)

-android-ndk pathAndroid NDK 根目录.   (默认 $ANDROID_NDK_ROOT)

-android-ndk-platform设置android 平台版本   (默认 android-9)

-android-ndk-host设置android NDK 主机类型 (linux-x86, linux-x86_64, etc.)   (默认 $ANDROID_NDK_HOST)

-android-arch设置android 体系结构 (armeabi, armeabi-v7a, x86, mips, arm64-v8a, x86_64, mips64)   (默认 armeabi-v7a)

-android-toolchain-version设置android 工具链版本   (默认 4.9)

-no-android-style-assets不编译 通过运行时设备自动提取style-assets的代码.  设置这将使Android风格的行为不当,但与lgpl2.1许可兼容
*-android-style-assets编译 通过运行时设备自动提取style-assets的代码. 此选项将使Android平台的lgpl2.1许可不兼容。

生成makefile

下面是我编译的时候使用的选项。 -platform这一个选项是用于指定目标平台的,可以看qt源码目录/qtbase/mkspecs/下的的目录,就是QT支持的平台。可以进这个目录修改qmake.conf文件来指定编译器和编译选项。

 /home/o/qt-src/qt-opensource-src-5.6.0/qt-everywhere-opensource-src-5.6.0 [o@o-pc] [12:09]
 
 > ./configure -prefix /home/o/pragram/qt_5.6.0_gcc5.2.1 -release -debug -opensource -c++std c++11 -static -qt-sql-mysql -qt-sql-sqlite -platform linux-g++-64  -qt-zlib -no-journald -qt-libpng -qt-libjpeg -openssl -opengl

下面是询问是否查看开源协议或者直接接受的。直接yes通过就好。

 Type ‘3‘ to view the GNU Lesser General Public License version 3.
 
 Type ‘L‘ to view the Lesser GNU General Public License version 2.1.
 
 Type ‘yes‘ to accept this license offer.
 
 Type ‘no‘ to decline this license offer.
 
 
 
 Do you accept the terms of either license? yes
 
 ... ...
遇到链接检查失败的情况

这里给出一个示例,就是xcb库检查失败。

 Running configuration tests (phase 1)...
 
 Done running configuration tests.
 
 Creating qmake...
 
 .Done.
 
 Running configuration tests (phase 2)...
 
 The test for linking against libxcb and support libraries failed!
 
  You might need to install dependency packages, or pass -qt-xcb.
 
  See src/plugins/platforms/xcb/README.

这个很好解决,按下libxcb-***-dev就是了。其他的库检查失败也是一样的。也可以通过-qt-xcb选项,使用Qt自带的xcb库。

生成makefile后进行编译

configure成功后会出现如下提示,后面说让你使用make进行编译,make install进行安装。“

Linux怎么编译qt

   1 Build type:    linux-g++-64 (x86_64, CPU features: mmx sse sse2)
   2
   3 Build options:
   4   Configuration .......... accessibility accessibility-atspi-bridge alsa audio-backend avx avx2 c++11 clock-gettime clock-monotonic compile_examples concurrent dbus dbus-linked debug egl eglfs egl_x11 enable_new_dtags evdev eventfd fontconfig full-config getaddrinfo getifaddrs gif glib gstreamer-0.10 harfbuzz iconv icu inotify ipv6ifname jpeg kms large-config largefile libudev linuxfb medium-config minimal-config mremap nis opengl openssl png posix_fallocate precompile_header pulseaudio qpa qpa reduce_exports reduce_relocations rpath small-config sse2 sse3 sse4_1 sse4_2 ssse3 static system-freetype threadsafe-cloexec use_gold_linker xcb xcb-glx xcb-plugin xcb-render xcb-sm xcb-xlib xinput2 xkbcommon-evdev xkbcommon-qt xlib xrender zlib
   5   Build parts ............ libs tools examples
   6   Mode ................... debug
   7   Using sanitizer(s)...... none
   8   Using C++ standard ..... c++11
   9   Using gold linker....... yes
  10   Using new DTAGS ........ yes
  11   Using PCH .............. yes
  12   Using LTCG ............. no
  13   Target compiler supports:
  14     SSE2/SSE3/SSSE3 ...... yes/yes/yes
  15     SSE4.1/SSE4.2 ........ yes/yes
  16     AVX/AVX2 ............. yes/yes
  17
  18 Qt modules and options:
  19   Qt D-Bus ............... yes (linked to dbus-1)
  20   Qt Concurrent .......... yes
  21   Qt GUI ................. yes
  22   Qt Widgets ............. yes
  23   Large File ............. yes
  24   QML debugging .......... yes
  25   Use system proxies ..... no
  26
  27 Support enabled for:
  28   Accessibility .......... yes
  29   ALSA ................... yes
  30   CUPS ................... no
  31   Evdev .................. yes
  32   FontConfig ............. yes
  33   FreeType ............... yes (system library)
  34   Glib ................... yes
  35   GStreamer .............. yes (0.10)
  36   GTK theme .............. no
  37   HarfBuzz ............... yes (bundled copy)
  38   Iconv .................. yes
  39   ICU .................... yes
  40   Image formats:
  41     GIF .................. yes (in QtGui, using bundled copy)
  42     JPEG ................. yes (in QtGui, using bundled copy)
  43     PNG .................. yes (in QtGui, using bundled copy)
  44   libinput................ no
  45   Logging backends:
  46     journald ............... no
  47     syslog   ............... no
  48   mtdev .................. no
  49   Networking:
  50     getaddrinfo .......... yes
  51     getifaddrs ........... yes
  52     IPv6 ifname .......... yes
  53     libproxy.............. no
  54     OpenSSL .............. yes (loading libraries at run-time)
  55   NIS .................... yes
  56   OpenGL / OpenVG:
  57     EGL .................. yes
  58     OpenGL ............... desktop
  59     OpenVG ............... no
  60   PCRE ................... system
  61   pkg-config ............. yes
  62   PulseAudio ............. yes
  63   QPA backends:
  64     DirectFB ............. no
  65     EGLFS ................ yes
  66       EGLFS i.MX6 ........ no
  67       EGLFS i.MX6 Wayland. no
  68       EGLFS EGLDevice .... no
  69       EGLFS GBM .......... no
  70       EGLFS Mali ......... no
  71       EGLFS Raspberry Pi . no
  72       EGLFS X11 .......... yes
  73     LinuxFB .............. yes
  74     Mir client............ no
  75     XCB .................. yes (system library)
  76       EGL on X ........... yes
  77       GLX ................ yes
  78       MIT-SHM ............ yes
  79       Xcb-Xlib ........... yes
  80       Xcursor ............ yes (loaded at runtime)
  81       Xfixes ............. yes (loaded at runtime)
  82       Xi ................. no
  83       Xi2 ................ yes
  84       Xinerama ........... yes (loaded at runtime)
  85       Xrandr ............. yes (loaded at runtime)
  86       Xrender ............ yes
  87       XKB ................ yes
  88       XShape ............. yes
  89       XSync .............. yes
  90       XVideo ............. yes
  91   Session management ..... yes
  92   SQL drivers:
  93     DB2 .................. no
  94     InterBase ............ no
  95     MySQL ................ qt
  96     OCI .................. no
  97     ODBC ................. yes (plugin)
  98     PostgreSQL ........... yes (plugin)
  99     SQLite 2 ............. no
 100     SQLite ............... qt-qt
 101     TDS .................. no
 102   tslib .................. no
 103   udev ................... yes
 104   xkbcommon-x11........... yes (bundled copy, XKB config root: /usr/share/X11/xkb)
 105   xkbcommon-evdev......... yes
 106   zlib ................... yes (bundled copy)
 107
 108
 109 WARNING: Using static linking will disable the use of dynamically
 110 loaded plugins. Make sure to import all needed static plugins,
 111 or compile needed modules into the library.
 112 Info: creating super cache file /home/o/qt-src/qt-opensource-src-5.6.0/qt-everywhere-opensource-src-5.6.0/.qmake.super
 113
 114 Qt is now configured for building. Just run ‘make‘.
 115 Once everything is built, you must run ‘make install‘.
 116 Qt will be installed into /home/o/pragram/qt_5.6.0_gcc5.2.1
 117
 118 Prior to reconfiguration, make sure you remove any leftovers from
 119 the previous build.

configure成功提示

关于“Linux怎么编译qt”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“Linux怎么编译qt”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI