Ubuntu 14.04系统下安装和编译QT 5.9.2库(桌面版/ARM嵌入式IMX6版)
最近要搞一個嵌入式項目,在I.MX6平臺上基于linux系統使用QT做界面開發,于是就研究了一下如何對QT 5.9.2版本的代碼進行下載和編譯。同時,因為編譯出來的程序不光要能在I.MX6嵌入式板子上運行,還要能夠在桌面端運行以方便調試,因此就涉及到桌面版和嵌入式版兩個版本,如下:
- pc桌面版,將其命名為qt-5.9.2-pc版本,用于在PC端模擬調試程序。
- imx6嵌入式版,將其命名為qt-5.9.2-imx6版本,用于在I.MX6平臺上運行程序。
下面就開始詳細介紹搭建、安裝、編譯等全過程的記錄。
一、準備工作
1、開發環境介紹
- 主機系統:win10(64位);
- 虛擬工具:Virtualbox 5.2.0;
- 虛擬系統:Ubuntu 14.04(64位);
2、下載QT源碼
直接去官網(http://download.qt.io/archive/qt/)下載QT的源碼即可。
由于某些歷史原因,我這里下載的是5.9.2版本。建議大家也同樣使用這個版本,畢竟我自己已經親自驗證過了。如果您使用新的版本,可能會遇到一些其他的問題。
這里需要注意的是,我們要下載的是源碼壓縮包,而不是現成編譯好的可執行文件。所以,請進入“single”目錄進行下載。我選擇的是后綴名為tar.xz的文件(因為它比較小),解壓得分兩步走,先解開xz,然后再解開tar,命令如下:
3、安裝編譯工具
請確保系統中已安裝gcc、g++和OpenGL。可使用以下命令進行測試并驗證它們的具體版本:
I、gcc工具
gcc --version如果沒有響應,或者提示gcc沒有安裝,則可以使用下述命令進行安裝:
sudo apt-get install build-essential安裝完成之后,同樣使用上述命令查看一下gcc的版本進行確認。
II、g++工具
g++ --version如果沒有響應,或者提示g++沒有安裝,則可以使用下述命令進行安裝:
sudo apt-get install g++安裝完成之后,同樣使用上述命令查看一下g++的版本進行確認。
III、OpenGL
glxinfo | grep OpenGL如果提示“程序“glxinfo”尚未安裝”,則可以使用下述命令進行安裝:
sudo apt-get install mesa-utils如果提示OpenGL找不到或者沒有安裝的話,則可使用下述命令安裝(具體的詳細過程可參見我的另外一篇博客:如何在Ubuntu 14.04下安裝OpenGL開發環境)。
sudo apt-get update sudo apt-get install build-essential sudo apt-get install libgl1-mesa-dev sudo apt-get install libglu1-mesa-dev sudo apt-get install libegl1-mesa-dev sudo apt-get install freeglut3-dev安裝完成之后,同樣使用上述命令查看一下OpenGL的版本進行確認。
4、搭建目錄環境
根據QT官方的說法,建議大家不要在QT源碼的目錄下直接進行編譯,這樣會污染源碼所在的目錄,無法達到多個版本共存編譯的效果。可以在QT源碼所在的同級目錄下,新建一個臨時用的編譯目錄,只為存放編譯腳本和編譯所產生的臨時文件。如下:
leon@Ubuntu:~/tempuse$ ll 總用量 20 drwxrwxr-x 4 leon leon 4096 8月 10 11:10 ./ drwxr-xr-x 30 leon leon 4096 8月 10 11:07 ../ drwxrwxr-x 43 leon leon 4096 10月 4 2017 qt-everywhere-opensource-src-5.9.2/leon@Ubuntu:~/tempuse$ mkdir qt-5.9.2-x11 qt-5.9.2-imx6leon@Ubuntu:~/tempuse$ ll 總用量 32 drwxrwxr-x 7 leon leon 4096 8月 10 11:13 ./ drwxr-xr-x 30 leon leon 4096 8月 10 11:07 ../ drwxrwxr-x 2 leon leon 4096 8月 10 11:13 qt-5.9.2-imx6/ drwxrwxr-x 2 leon leon 4096 8月 10 11:13 qt-5.9.2-pc/ drwxrwxr-x 43 leon leon 4096 10月 4 2017 qt-everywhere-opensource-src-5.9.2/于是,可以分別在qt-5.9.2-x11 qt-5.9.2-imx6這2個目錄下進行不同版本的代碼編譯,而不會影響到源碼所在的目錄。
5、目標文件系統
由于最終編譯出來的程序是要運行在I.MX6的嵌入式系統中,因此在編譯的過程中要引入目標文件系統。我這里將該文件系統(fsl-image-gui-imx6qsabresd)解壓放在/opt目錄下。請記住這個目錄,后面會用的到。
leon@Ubuntu:~$ cd /opt leon@Ubuntu:/opt$ ll 總用量 32 drwxr-xr-x 8 root root 4096 8月 10 13:39 ./ drwxr-xr-x 23 root root 4096 10月 11 2017 ../ drwxr-xr-x 19 leon leon 4096 11月 14 2017 fsl-image-gui-imx6qsabresd/ drwxr-xr-x 9 root root 4096 10月 11 2017 VBoxGuestAdditions-5.0.20/ drwxr-xr-x 6 root root 4096 6月 9 2017 wps-office_10.1.0.5707~a21_x86_64/二、pc桌面版
1、創建配置腳本
進入qt-5.9.2-pc目錄,新建config.sh文件,輸入:
#!/bin/sh./../qt-everywhere-opensource-src-5.9.2/configure \-verbose \-opensource \-release \-shared \-confirm-license \-make libs \-no-feature-cursor \-no-qml-debug \-no-use-gold-linker \-no-iconv \-no-glib \-no-gstreamer \-prefix /opt/qt-5.9.2-pc這里“-prefix /opt/qt-5.9.2-pc“是用于指定編譯之后庫文件所安裝的位置,你可以按照你自己的規劃和要求來更改,但是其他的指令不建議更改。
為config.sh文件增加可運行屬性,并運行之。大約1-2分鐘之后,結束,提示配置成功:
Configure summary:Build type: linux-g++ (x86_64, CPU features: mmx sse sse2) Configuration: sse2 sse3 ssse3 sse4_1 sse4_2 avx avx2 compile_examples enable_new_dtags f16c largefile precompile_header shared rpath release c++11 concurrent dbus no-qml-debug reduce_exports reduce_relocations stl Build options:Mode ................................... releaseOptimize release build for size ........ noBuilding shared libraries .............. yesUsing C++ standard ..................... C++11Using ccache ........................... noUsing gold linker ...................... noUsing new DTAGS ........................ yesUsing precompiled headers .............. yesUsing LTCG ............................. noTarget compiler supports:SSE .................................. SSE2 SSE3 SSSE3 SSE4.1 SSE4.2AVX .................................. AVX AVX2 F16CAVX512 ............................... <none>Build parts ............................ libs Qt modules and options:Qt Concurrent .......................... yesQt D-Bus ............................... yesQt D-Bus directly linked to libdbus .... noQt Gui ................................. yesQt Network ............................. yesQt Sql ................................. yesQt Testlib ............................. yesQt Widgets ............................. yesQt Xml ................................. yes Support enabled for:Using pkg-config ....................... yesQML debugging .......................... noudev ................................... noUsing system zlib ...................... yes Qt Core:DoubleConversion ....................... yesUsing system DoubleConversion ........ noGLib ................................... noiconv .................................. noICU .................................... noLogging backends:journald ............................. nosyslog ............................... noslog2 ................................ noUsing system PCRE2 ..................... no Qt Network:getaddrinfo() .......................... yesgetifaddrs() ........................... yesIPv6 ifname ............................ yeslibproxy ............................... noOpenSSL ................................ noQt directly linked to OpenSSL ........ noSCTP ................................... noUse system proxies ..................... yes Qt Gui:Accessibility .......................... yesFreeType ............................... yesUsing system FreeType ................ noHarfBuzz ............................... yesUsing system HarfBuzz ................ noFontconfig ............................. noImage formats:GIF .................................. yesICO .................................. yesJPEG ................................. yesUsing system libjpeg ............... noPNG .................................. yesUsing system libpng ................ noEGL .................................... yesOpenVG ................................. noOpenGL:Desktop OpenGL ....................... yesOpenGL ES 2.0 ........................ noOpenGL ES 3.0 ........................ noOpenGL ES 3.1 ........................ noSession Management ..................... yes Features used by QPA backends:evdev .................................. yeslibinput ............................... noINTEGRITY HID .......................... nomtdev .................................. notslib .................................. noxkbcommon-evdev ........................ no QPA backends:DirectFB ............................... noEGLFS .................................. yesEGLFS details:EGLFS i.Mx6 .......................... noEGLFS i.Mx6 Wayland .................. noEGLFS EGLDevice ...................... noEGLFS GBM ............................ noEGLFS Mali ........................... noEGLFS Raspberry Pi ................... noEGL on X11 ........................... yesLinuxFB ................................ yesVNC .................................... yesMir client ............................. noX11:Using system-provided XCB libraries .. noEGL on X11 ........................... yesXinput2 .............................. noXCB XKB .............................. yesXLib ................................. yesXCB render ........................... yesXCB GLX .............................. yesXCB Xlib ............................. yesUsing system-provided xkbcommon ...... no Qt Widgets:GTK+ ................................... noStyles ................................. Fusion Windows Qt PrintSupport:CUPS ................................... no Qt Sql:DB2 (IBM) .............................. noInterBase .............................. noMySql .................................. noOCI (Oracle) ........................... noODBC ................................... noPostgreSQL ............................. noSQLite2 ................................ noSQLite ................................. yesUsing system provided SQLite ......... noTDS (Sybase) ........................... no Qt SerialBus:Socket CAN ............................. yesSocket CAN FD .......................... yes QtXmlPatterns:XML schema support ..................... yes Qt QML:QML interpreter ........................ yesQML network support .................... yes Qt Quick:Direct3D 12 ............................ noAnimatedImage item ..................... yesCanvas item ............................ yesSupport for Qt Quick Designer .......... yesFlipable item .......................... yesGridView item .......................... yesListView item .......................... yesPath support ........................... yesPathView item .......................... yesPositioner items ....................... yesShaderEffect item ...................... yesSprite item ............................ yes Qt Gamepad:SDL2 ................................... no Qt 3D:Assimp ................................. yesSystem Assimp .......................... noOutput Qt3D Job traces ................. noOutput Qt3D GL traces .................. no Qt 3D GeometryLoaders:Autodesk FBX ........................... no Qt Wayland Client ........................ no Qt Wayland Compositor .................... no Qt Bluetooth:BlueZ .................................. noBlueZ Low Energy ....................... noLinux Crypto API ....................... no Qt Sensors:sensorfw ............................... no Qt Quick Controls 2:Styles ................................. Default Material Universal Qt Quick Templates 2:Hover support .......................... yesMulti-touch support .................... yes Qt Positioning:Gypsy GPS Daemon ....................... noWinRT Geolocation API .................. no Qt Location:Geoservice plugins:OpenStreetMap ........................ yesHERE ................................. yesEsri ................................. yesMapbox ............................... yesMapboxGL ............................. noItemsoverlay ......................... yes Qt Multimedia:ALSA ................................... noGStreamer 1.0 .......................... noGStreamer 0.10 ......................... noVideo for Linux ........................ yesOpenAL ................................. noPulseAudio ............................. noResource Policy (libresourceqt5) ....... noWindows Audio Services ................. noDirectShow ............................. noWindows Media Foundation ............... no Qt WebEngine:Embedded build ......................... noPepper Plugins ......................... yesPrinting and PDF ....................... yesProprietary Codecs ..................... noSpellchecker ........................... yesWebRTC ................................. yesUsing system ninja ..................... noALSA ................................... noPulseAudio ............................. noSystem libraries:re2 .................................. noICU .................................. nolibwebp and libwebpdemux ............. noOpus ................................. noffmpeg ............................... noNote: Also available for Linux: linux-clang linux-iccNote: Disabling X11 Accessibility Bridge: D-Bus or AT-SPI is missing.Qt is now configured for building. Just run 'make'. Once everything is built, you must run 'make install'. Qt will be installed into '/opt/qt-5.9.2-pc'.Prior to reconfiguration, make sure you remove any leftovers from the previous build.說明:配置的過程中,經過我自己的親測,有可能會提示一些錯誤信息,包括下面的make環節和install環節,都有可能會提示一些錯誤信息。但是只要程序不會自動終止,一般就問題不大。
2、編譯和安裝
輸入下述命令開始編譯。由于源碼內容較多,編譯時間會很長,以我的電腦i3-4160 3.6GHz處理器+4G內存的配置,編譯了差不多60分鐘。
make -j4 -s # -s表示靜默輸出,只提示一些錯誤和警告編譯完成后,輸入下述命令便可直接安裝到之前預設的目錄下:
sudo make install # sudo是為了提升權限,如果你的權限夠可以不用三、imx6嵌入式版
1、修改qmake文件
修改qt源碼目錄下的qtbase/mkspecs/linux-arm-gnueabi-g++目錄下的文件qmake.conf文件為以下內容:
# # qmake configuration for building with arm-linux-gnueabi-g++ #MAKEFILE_GENERATOR = UNIX CONFIG += incremental QMAKE_INCREMENTAL_STYLE = sublibIMX6_CFLAGS = -march=armv7-a -mfpu=neon -DLINUX=1 -DEGL_API_FB=1 IMX6_CFLAGS_RELEASE = -O2 $$IMX6_CFLAGS QMAKE_CFLAGS_DEBUG += $$IMX6_CFLAGS QMAKE_CXXFLAGS_DEBUG += $$IMX6_CFLAGS QMAKE_CFLAGS_RELEASE += $$IMX6_CFLAGS_RELEASE QMAKE_CXXFLAGS_RELEASE += $$IMX6_CFLAGS_RELEASEinclude(../common/linux.conf) include(../common/gcc-base-unix.conf) include(../common/g++-unix.conf)POKY_PATH = /opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi ROOTFS_PATH = /opt/fsl-image-gui-imx6qsabresd# modifications to g++.conf QMAKE_CC = $$POKY_PATH/arm-poky-linux-gnueabi-gcc -mfloat-abi=hard QMAKE_CXX = $$POKY_PATH/arm-poky-linux-gnueabi-g++ -mfloat-abi=hard QMAKE_LINK = $$POKY_PATH/arm-poky-linux-gnueabi-g++ -mfloat-abi=hard QMAKE_LINK_SHLIB = $$POKY_PATH/arm-poky-linux-gnueabi-g++ -mfloat-abi=hard# modifications to linux.conf QMAKE_AR = $$POKY_PATH/arm-poky-linux-gnueabi-ar cqs QMAKE_OBJCOPY = $$POKY_PATH/arm-poky-linux-gnueabi-objcopy QMAKE_NM = $$POKY_PATH/arm-poky-linux-gnueabi-nm -P QMAKE_STRIP = $$POKY_PATH/arm-poky-linux-gnueabi-stripQMAKE_INCDIR += $$ROOTFS_PATH/usr/include QMAKE_LIBDIR += $$ROOTFS_PATH/usr/libQMAKE_LIBS_EGL += -lEGL -lGAL QMAKE_LIBS_OPENGL_ES1 += -lGLESv1_CM -lEGL -lGAL QMAKE_LIBS_OPENGL_ES1CL += -lGLES_CL -lEGL -lGAL QMAKE_LIBS_OPENGL_ES2 += -lGLESv2 -lEGL -lGAL -lVSC QMAKE_LIBS_OPENVG += -lOpenVG -lEGL -lGAL -lVSCload(qt_config)2、創建配置腳本
進入qt-5.9.2-imx6目錄,新建config.sh文件,輸入:
#!/bin/sh./../qt-everywhere-opensource-src-5.9.2/configure \ -verbose \ -opensource \ -release \ -shared \ -confirm-license \ -eglfs \ -linuxfb \ -openvg \ -make libs \ -no-feature-cursor \ -no-qml-debug \ -no-use-gold-linker \ -no-iconv \ -xplatform linux-arm-gnueabi-g++ \ -prefix /opt/qt-5.9.2-imx6 \ -I/opt/fsl-image-gui-imx6qsabresd/usr/include \ -L/opt/fsl-image-gui-imx6qsabresd/usr/lib這里“-prefix /opt/qt-5.9.2-imx6“是用于指定編譯之后庫文件所安裝的位置,你可以按照你自己的規劃和要求來更改,后面兩句話則是用于指定I.MX6文件系統所在的目錄位置,你也可以根據你自己的情況修改。但是其他的指令不建議更改。
為config.sh文件增加可運行屬性,并運行之。大約1-2分鐘之后,結束,提示配置成功:
Configure summary:Building on: linux-g++ (x86_64, CPU features: mmx sse sse2) Building for: linux-arm-gnueabi-g++ (arm, CPU features: neon) Configuration: cross_compile compile_examples enable_new_dtags largefile neon precompile_header shared rpath release c++11 c++14 concurrent dbus no-pkg-config no-qml-debug reduce_exports stl Build options:Mode ................................... releaseOptimize release build for size ........ noBuilding shared libraries .............. yesUsing C++ standard ..................... C++14Using ccache ........................... noUsing gold linker ...................... noUsing new DTAGS ........................ yesUsing precompiled headers .............. yesUsing LTCG ............................. noTarget compiler supports:NEON ................................. yesBuild parts ............................ libs Qt modules and options:Qt Concurrent .......................... yesQt D-Bus ............................... yesQt D-Bus directly linked to libdbus .... noQt Gui ................................. yesQt Network ............................. yesQt Sql ................................. yesQt Testlib ............................. yesQt Widgets ............................. yesQt Xml ................................. yes Support enabled for:Using pkg-config ....................... noQML debugging .......................... noudev ................................... noUsing system zlib ...................... no Qt Core:DoubleConversion ....................... yesUsing system DoubleConversion ........ noGLib ................................... noiconv .................................. noICU .................................... noLogging backends:journald ............................. nosyslog ............................... noslog2 ................................ noUsing system PCRE2 ..................... no Qt Network:getaddrinfo() .......................... yesgetifaddrs() ........................... yesIPv6 ifname ............................ yeslibproxy ............................... noOpenSSL ................................ noQt directly linked to OpenSSL ........ noSCTP ................................... noUse system proxies ..................... yes Qt Gui:Accessibility .......................... yesFreeType ............................... yesUsing system FreeType ................ noHarfBuzz ............................... yesUsing system HarfBuzz ................ noFontconfig ............................. noImage formats:GIF .................................. yesICO .................................. yesJPEG ................................. yesUsing system libjpeg ............... noPNG .................................. yesUsing system libpng ................ noEGL .................................... yesOpenVG ................................. yesOpenGL:Desktop OpenGL ....................... noOpenGL ES 2.0 ........................ yesOpenGL ES 3.0 ........................ yesOpenGL ES 3.1 ........................ noSession Management ..................... yes Features used by QPA backends:evdev .................................. yeslibinput ............................... noINTEGRITY HID .......................... nomtdev .................................. notslib .................................. noxkbcommon-evdev ........................ no QPA backends:DirectFB ............................... noEGLFS .................................. yesEGLFS details:EGLFS i.Mx6 .......................... yesEGLFS i.Mx6 Wayland .................. noEGLFS EGLDevice ...................... noEGLFS GBM ............................ noEGLFS Mali ........................... noEGLFS Raspberry Pi ................... noEGL on X11 ........................... noLinuxFB ................................ yesVNC .................................... yesMir client ............................. no Qt Widgets:GTK+ ................................... noStyles ................................. Fusion Windows Qt PrintSupport:CUPS ................................... no Qt Sql:DB2 (IBM) .............................. noInterBase .............................. noMySql .................................. noOCI (Oracle) ........................... noODBC ................................... noPostgreSQL ............................. noSQLite2 ................................ noSQLite ................................. yesUsing system provided SQLite ......... noTDS (Sybase) ........................... no Qt SerialBus:Socket CAN ............................. yesSocket CAN FD .......................... yes QtXmlPatterns:XML schema support ..................... yes Qt QML:QML interpreter ........................ yesQML network support .................... yes Qt Quick:Direct3D 12 ............................ noAnimatedImage item ..................... yesCanvas item ............................ yesSupport for Qt Quick Designer .......... yesFlipable item .......................... yesGridView item .......................... yesListView item .......................... yesPath support ........................... yesPathView item .......................... yesPositioner items ....................... yesShaderEffect item ...................... yesSprite item ............................ yes Qt Gamepad:SDL2 ................................... no Qt 3D:Assimp ................................. yesSystem Assimp .......................... noOutput Qt3D Job traces ................. noOutput Qt3D GL traces .................. no Qt 3D GeometryLoaders:Autodesk FBX ........................... no Qt Wayland Client ........................ no Qt Wayland Compositor .................... no Qt Bluetooth:BlueZ .................................. noBlueZ Low Energy ....................... noLinux Crypto API ....................... no Qt Sensors:sensorfw ............................... no Qt Quick Controls 2:Styles ................................. Default Material Universal Qt Quick Templates 2:Hover support .......................... yesMulti-touch support .................... yes Qt Positioning:Gypsy GPS Daemon ....................... noWinRT Geolocation API .................. no Qt Location:Geoservice plugins:OpenStreetMap ........................ yesHERE ................................. yesEsri ................................. yesMapbox ............................... yesMapboxGL ............................. yesItemsoverlay ......................... yes Qt Multimedia:ALSA ................................... noGStreamer 1.0 .......................... noGStreamer 0.10 ......................... noVideo for Linux ........................ yesOpenAL ................................. noPulseAudio ............................. noResource Policy (libresourceqt5) ....... noWindows Audio Services ................. noDirectShow ............................. noWindows Media Foundation ............... no Qt WebEngine:Embedded build ......................... yesPepper Plugins ......................... noPrinting and PDF ....................... noProprietary Codecs ..................... noSpellchecker ........................... yesWebRTC ................................. noUsing system ninja ..................... noALSA ................................... noPulseAudio ............................. noSystem libraries:re2 .................................. noICU .................................. nolibwebp and libwebpdemux ............. noOpus ................................. noffmpeg ............................... noNote: Also available for Linux: linux-clang linux-iccNote: No wayland-egl support detected. Cross-toolkit compatibility disabled.WARNING: Cross compiling without sysroot. Disabling pkg-configQt is now configured for building. Just run 'make'. Once everything is built, you must run 'make install'. Qt will be installed into '/opt/qt-5.9.2-imx6'.Prior to reconfiguration, make sure you remove any leftovers from the previous build.說明:配置的過程中,經過我自己的親測,有可能會提示一些錯誤信息,包括下面的make環節和install環節,都有可能會提示一些錯誤信息。但是只要程序不會自動終止,一般就問題不大。
3、編譯和安裝
輸入下述命令開始編譯。由于源碼內容較多,編譯時間會很長,以我的電腦i3-4160 3.6GHz處理器+4G內存的配置,編譯了差不多90分鐘。
make -j4 -s # -s表示靜默輸出映射,只提示一些警告和錯誤編譯完成后,輸入下述命令便可直接安裝到之前預設的目錄下:
sudo make install # sudo是為了提升權限,如果你的權限夠可以不用四、寫在后面
至此,桌面版和嵌入式版共2個版本的QT庫全部編譯和安裝完成,分別位于opt目錄下的指定位置。接下去就是安裝QTCreator,然后在其中配置好相關的套件環境即可,在此不做記錄。有需要的同學可參見我的其他博客中的記錄。
leon@Ubuntu:~$ cd /opt leon@Ubuntu:/opt$ ll 總用量 40 drwxr-xr-x 10 root root 4096 8月 10 16:20 ./ drwxr-xr-x 23 root root 4096 10月 11 2017 ../ drwxr-xr-x 19 leon leon 4096 11月 14 2017 fsl-image-gui-imx6qsabresd/ drwxr-xr-x 10 root root 4096 8月 10 14:42 qt-5.9.2-imx6/ drwxr-xr-x 10 root root 4096 8月 10 13:40 qt-5.9.2-pc/ drwxr-xr-x 9 root root 4096 10月 11 2017 VBoxGuestAdditions-5.0.20/ drwxr-xr-x 6 root root 4096 6月 9 2017 wps-office_10.1.0.5707~a21_x86_64/ 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Ubuntu 14.04系统下安装和编译QT 5.9.2库(桌面版/ARM嵌入式IMX6版)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AMD 未曾忘记 Radeon RX 6
- 下一篇: 填补国内空白,我国首台抛雪机亮相京新高速