1. 程式人生 > >qt-5.6.0 移植之qt原始碼編譯-configure選項

qt-5.6.0 移植之qt原始碼編譯-configure選項

其實這只是給自己看的一個configure選項筆記,沒有太多的東西。

首先: 下載qt5.6的原始碼:

    地址: http://download.qt.io/archive/qt/5.6/

    下載完解壓: tar  -xvf   qt-everywhere-opensource-src-5.6.0.tar.gz

    解壓完進入原始碼 : 修改幾個東西:

      1. 進入qtbase/mkspecs 裡面, 複製一份linux-arm-gnueabi-g++    ,名字為linux-arm

        在進入 linux-arm 裡面, vi  qmake.conf , 把裡面的程式碼改為自己平臺架構以及自己交叉編譯器,我的更改如下:

複製程式碼
 1 #                                                                               
 2 # qmake configuration for building with arm-linux-gnueabi-g++                   
 3 #                                                                               
 4                                                                                 
 5
MAKEFILE_GENERATOR = UNIX 6 CONFIG += incremental 7 QMAKE_INCREMENTAL_STYLE = sublib 8 9
QT_QPA_DEFAULT_PLATFORM = linuxfb 10 QMAKE_CFLAGS_RELEASE += -O2 -march=armv7-a 11 QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv7-a 12 13 QMAKE_INCDIR += $(TSLIB)/include 14 QMAKE_LIBDIR += $(TSLIB)/lib 15 16 include(../common/linux.conf) 17 include(../common/gcc-base-unix.conf) 18 include(../common/g++-unix.conf) 19 20 # modifications to g++.conf 21 QMAKE_CC = arm-arago-linux-gnueabi-gcc 22 QMAKE_CXX = arm-arago-linux-gnueabi-g++ 23 QMAKE_LINK = arm-arago-linux-gnueabi-g++ 24 QMAKE_LINK_SHLIB = arm-arago-linux-gnueabi-g++ 25 # modifications to linux.conf 26 QMAKE_AR = arm-arago-linux-gnueabi-ar cqs 27 QMAKE_OBJCOPY = arm-arago-linux-gnueabi-objcopy 28 QMAKE_NM = arm-arago-linux-gnueabi-nm -P 29 QMAKE_STRIP = arm-arago-linux-gnueabi-strip 30 load(qt_config) 31 ~
複製程式碼

    我的架構是armv7-a , 我的交叉編譯器的字首是  arm-arago-linux-gnueabi-

    可能你們的架構有可能是armv5 的, 交叉編譯器可能是  arm-none-linux-gnueabi- 的,在這裡提醒大家要注意了。

改完這些回到頂層目錄,分析configure  的選項。我今天準備一個個分析。

在qt5.6 原始碼頂層目錄下 , 敲: ./configure --help , 它就會把所有的configure的選項都羅列出來:

下面來一個個分析:

    -prefix <dir> ...... The deployment directory, as seen on the target device.
                         (default /usr/local/Qt-5.6.0, $PWD if -developer-build is active) 

    第一個引數: -prefix <dir> 這個指定 make 完成後make install 的目錄,不指定的話預設是/usr/local/Qt-5.6.0

    -extprefix <dir> ... The installation directory, as seen on the host machine.
                         (default SYSROOT/PREFIX)                               
     -hostprefix [dir] .. The installation directory for build tools running on the 
                         host machine. If [dir] is not given, the current build 
                         directory will be used. (default EXTPREFIX)  

    這兩個引數就沒有什麼好介紹的了, 一個是如果指定了sysroot 目錄, 他會去安裝了sysroot/$PREFIX 目錄下,一個是直接安裝到$EXTPREFIX目錄。

複製程式碼
 You may use these to change the layout of the install. Note that all directories
 except -sysconfdir should be located under -prefix/-hostprefix:                
                                                                                
    -bindir <dir> ......... User executables will be installed to <dir>         
                            (default PREFIX/bin)                                
    -headerdir <dir> ...... Headers will be installed to <dir>                  
                            (default PREFIX/include)                            
    -libdir <dir> ......... Libraries will be installed to <dir>                
                            (default PREFIX/lib)                                
    -archdatadir <dir> .... Arch-dependent data used by Qt will be installed to <dir>
                            (default PREFIX)                                    
    -plugindir <dir> ...... Plugins will be installed to <dir>                  
                            (default ARCHDATADIR/plugins)                       
    -libexecdir <dir> ..... Program executables will be installed to <dir>      
                            (default ARCHDATADIR/libexec, ARCHDATADIR/bin for MinGW)
    -importdir <dir> ...... Imports for QML1 will be installed to <dir>         
                            (default ARCHDATADIR/imports)                       
    -qmldir <dir> ......... Imports for QML2 will be installed to <dir>         
                            (default ARCHDATADIR/qml)                           
    -datadir <dir> ........ Arch-independent data used by Qt will be installed to <dir>
                            (default PREFIX)                                    
    -docdir <dir> ......... Documentation will be installed to <dir>            
                            (default DATADIR/doc)                               
    -translationdir <dir> . Translations of Qt programs will be installed to <dir>
                            (default DATADIR/translations)                      
    -sysconfdir <dir> ..... Settings used by Qt programs will be looked for in <dir>
                            (default PREFIX/etc/xdg)                            
    -examplesdir <dir> .... Examples will be installed to <dir>                 
                            (default PREFIX/examples)                           
    -testsdir <dir> ....... Tests will be installed to <dir>                    
                            (default PREFIX/tests)                              
                                                                                
    -hostbindir <dir> .. Host executables will be installed to <dir>            
                         (default HOSTPREFIX/bin)                               
    -hostlibdir <dir> .. Host libraries will be installed to <dir>              
                         (default HOSTPREFIX/lib)                               
    -hostdatadir <dir> . Data used by qmake will be installed to <dir>          
                         (default HOSTPREFIX)                                   
複製程式碼

    這些選項的話是可以改變你的你的所有子目錄的安裝目錄。 比如說Qt-5.6.0/bin 的安裝目錄或是其實的一些目錄

    下面是一些配置選項:

複製程式碼
*   -release ........... Compile and link Qt with debugging turned off.         
    -debug ............. Compile and link Qt with debugging turned on.          
    -debug-and-release . Compile and link two versions of Qt, with and without  
                         debugging turned on (Mac only).                        
                                                                                
    -force-debug-info .. Create symbol files for release builds.                
                                                                                
    -developer-build ... Compile and link Qt with Qt developer options (including auto-tests exporting)
複製程式碼

    第一個,--release  編譯以及連結qt  但是關閉除錯。一般的話交叉編譯qt的原始碼都選擇這個選項。

        -debug , 開啟除錯的介面

        -debug-and-release 編譯成上面連個版本。

        -force-debug-info 建立字元檔案為了記錄版本(不知道是不是正確,沒有驗證過)。

        -developer-build  編譯和連結qt 而且加入開發者選項(包含自己測試輸出)。

複製程式碼
 *  -no-optimized-tools ... Do not build optimized host tools even in debug build.
    -optimized-tools ...... Build optimized host tools even in debug build.     
                                                                                
    -opensource ........ Compile and link the Open-Source Edition of Qt.        
    -commercial ........ Compile and link the Commercial Edition of Qt.         
                                                                                
    -confirm-license ... Automatically acknowledge the license (use with        
                         either -opensource or -commercial)                     
                                                                                
    -c++std <edition> .. Compile Qt with C++ standard edition (c++98, c++11, c++14, c++1z)
                         Default: highest supported                             
                                                                                
複製程式碼

        前面兩個是 是否要建立優化主工具當除錯的時候,一般我會選擇 -no-optimized-tools

        -opensource  編譯和連結開源QT版本,一般的話我們都是使用的開源的QT版本。

        -commercial  編譯和連結商業QT版本。

        -onfirm-license 自動確認是否是開源還是商業的。

        -c++std <>  編譯QT 是使用的什麼版本的c++ ,預設為最高版本

複製程式碼
 *  -shared ............ Create and use shared Qt libraries.                    
    -static ............ Create and use static Qt libraries.                    
                                                                                
    -no-largefile ...... Disables large file support.                           
 +  -largefile ......... Enables Qt to access files larger than 4 GB.           
                                                                                
    -no-accessibility .. Do not compile Accessibility support.                  
                         Disabling accessibility is not recommended, as it will break QStyle
                         and may break other internal parts of Qt.              
                         With this switch you create a source incompatible version of Qt,
                         which is unsupported.                                  
 +  -accessibility ..... Compile Accessibility support.                         
                                                                                
    -no-sql-<driver> ... Disable SQL <driver> entirely.                         
    -qt-sql-<driver> ... Enable a SQL <driver> in the Qt SQL module, by default 
                         none are turned on.                                    
複製程式碼

        第一個比較容易理解: 是編譯成動態庫還是靜態庫,一般的話我們編譯的都是動態庫,這樣的話軟體的大小不會那麼大, 選擇的是 -shared

        第二個是是否允許大檔案支援, 這個我還沒沒有試過。 一般我選擇的都是預設的,預設是 -largefile

        第三個是易接近支援, 因為不同版本的qt都做了一些相關的改動, 一般的話我都選擇預設, 這樣的話可以提高軟體的可移植性。 -accessibility

        第四個是SQL 驅動模組的指定。我這裡是沒有這個模組的驅動的,所以我不去指定這個選項一般

複製程式碼
    -plugin-sql-<driver> Enable SQL <driver> as a plugin to be linked to        
                         at run time.                                           
                                                                                
                         Possible values for <driver>:                          
                         [ db2 ibase mysql oci odbc psql sqlite sqlite2 tds ]   
                                                                                
    -system-sqlite ..... Use sqlite from the operating system.                  
                                                                                
    -no-qml-debug ...... Do not build the in-process QML debugging support.     
 +  -qml-debug ......... Build the QML debugging support.                       
                                                                                
    -platform target ... The operating system and compiler you are building     
                         on (default detected from host system).                
                                                                                
                         See the README file for a list of supported            
                         operating systems and compilers.                       
                                                                                
複製程式碼

         前面兩個還是關於sql 的。一個允許sql作為一個外掛在執行的時候,一個使用系統的sqlite 

         下面那個是指定是否編譯QML 除錯支援, 一般我選擇的是:-no-qml-debug

         第三塊是選擇目標平臺:預設是選擇本機的作業系統, 閱讀頂層目錄的readme 可以知道支援哪些作業系統。

複製程式碼
   -no-sse2 ........... Do not compile with use of SSE2 instructions.          
    -no-sse3 ........... Do not compile with use of SSE3 instructions.          
    -no-ssse3 .......... Do not compile with use of SSSE3 instructions.         
    -no-sse4.1 ......... Do not compile with use of SSE4.1 instructions.        
    -no-sse4.2 ......... Do not compile with use of SSE4.2 instructions.        
    -no-avx ............ Do not compile with use of AVX instructions.           
    -no-avx2 ........... Do not compile with use of AVX2 instructions.          
    -no-mips_dsp ....... Do not compile with use of MIPS DSP instructions.      
    -no-mips_dspr2 ..... Do not compile with use of MIPS DSP rev2 instructions. 
複製程式碼

        這些選項我都沒有研究過是幹嘛的。所以我一般我不指定他

複製程式碼
    -qtnamespace <name>  Wraps all Qt library code in 'namespace <name> {...}'. 
    -qtlibinfix <infix>  Renames all libQt*.so to libQt*<infix>.so.             
                                                                                
    -testcocoon ........ Instrument Qt with the TestCocoon code coverage tool.  
    -gcov .............. Instrument Qt with the GCov code coverage tool.        
                                                                                
    -D <string> ........ Add an explicit define to the preprocessor.            
    -I <string> ........ Add an explicit include path.                          
    -L <string> ........ Add an explicit library path.                          
複製程式碼

        第一個是qt名稱空間的, 一般不修改。

        第二個是對qt庫的重新命名,加一些字尾。一般我們也用不到。

        第三第四個是關於testcocoon 和 GCov的工具,一般我也不會去指定

        後面三個第一個是 在預處理的時候加一個字首,第二個是新增一個額外的標頭檔案目錄,第三個是新增一個額外的庫目錄

複製程式碼
 +  -pkg-config ........ Use pkg-config to detect include and library paths. By default,
                         configure determines whether to use pkg-config or not with
                         some heuristics such as checking the environment variables.
    -no-pkg-config ..... Disable use of pkg-config.                             
    -force-pkg-config .. Force usage of pkg-config (skips pkg-config usability  
                         detection heuristic).                                  
                                                                                
    -help, -h .......... Display this information.                              
                                                                                
複製程式碼

         第一個是指定是否支援pkg-config  它回去尋找屬於你的標頭檔案以及庫,後面還有一個強迫使用,意思就是必須使用。

         第二個是列印幫助。

下面是第三方庫的問題。這個東西相當的麻煩,說句實話,我就是因為這個問題停在這裡兩天了。所以我才來跟一下這個配置選項,看一下是不是我的配置出了問題

複製程式碼
Third Party Libraries:                                                          
                                                                                
    -qt-zlib ............ Use the zlib bundled with Qt.                         
 +  -system-zlib ........ Use zlib from the operating system.                   
                          See http://www.gzip.org/zlib                          
                                                                                
    -no-mtdev ........... Do not compile mtdev support.                         
 +  -mtdev .............. Enable mtdev support.                                 
                                                                                
 +  -no-journald ........ Do not send logging output to journald.               
    -journald ........... Send logging output to journald.                      
                                                                                
 +  -no-syslog .......... Do not send logging output to syslog.                 
    -syslog ............. Send logging output to syslog.                        
                                                                                
    -no-gif ............. Do not compile GIF reading support.                   
                                                                                
    -no-libpng .......... Do not compile PNG support.                           
    -qt-libpng .......... Use the libpng bundled with Qt.                       
 +  -system-libpng ...... Use libpng from the operating system.                 
                          See http://www.libpng.org/pub/png                     
                                                                                
    -no-libjpeg ......... Do not compile JPEG support.                          
    -qt-libjpeg ......... Use the libjpeg bundled with Qt.                      
 +  -system-libjpeg ..... Use libjpeg from the operating system.                
                          See http://www.ijg.org                                
複製程式碼

      第一個是zlib 庫, 預設是系統的zlib , 但是我們要選 -qt-zlib ,不要問我為什麼, 因為我現在是在做移植,系統的是X86架構的,板子不一樣。

      第二個是mtdev 支援, 是觸控式螢幕多點控制協議的支援。如果你的觸控式螢幕要多點控制,那就加上。 -medev.

      第三個是輸入日誌支援,有必要的話可以加上。 -syslog , 一般的話我選擇預設。

      第四個是指定沒有gif 閱讀功能 , 我都不需要這個功能, 所以我會加上 -no-gif。

      第五個是指定是否支援PNG 這個我一般也是會加上 -no-libpng , 或者是-qt-libpng。

      第六個是指定jpeg 庫支援, 和上面那個同理,-no-libjpeg或者是 -qt-libjpeg。

複製程式碼
    -no-freetype ........ Do not compile in Freetype2 support.                  
    -qt-freetype ........ Use the libfreetype bundled with Qt.                  
 +  -system-freetype..... Use the libfreetype provided by the system (enabled if -fontconfig is active).
                          See http://www.freetype.org                           
                                                                                
    -no-harfbuzz ........ Do not compile HarfBuzz-NG support.                   
 *  -qt-harfbuzz ........ Use HarfBuzz-NG bundled with Qt to do text shaping.   
                          It can still be disabled by setting                   
                          the QT_HARFBUZZ environment variable to "old".        
    -system-harfbuzz .... Use HarfBuzz-NG from the operating system             
                          to do text shaping. It can still be disabled          
                          by setting the QT_HARFBUZZ environment variable to "old".
                          See http://www.harfbuzz.org                           
                                                                                
    -no-openssl ......... Do not compile support for OpenSSL.                   
 +  -openssl ............ Enable run-time OpenSSL support.                      
    -openssl-linked ..... Enabled linked OpenSSL support.                       
                                                                                
    -no-libproxy ....... Do not compile support for libproxy                    
 +  -libproxy .......... Use libproxy from the operating system.                
複製程式碼

       第一個是 freetype2 的編譯支援。 一般我會選擇-no-freetype 或者是-qt-freetype . 原則是隻要是有關作業系統,最好不要有system 字眼。

       第二個是有關字型的。一般我會選擇-qt-harfbuzz.

       第三個是 openssl ,一般我會選擇-no-openssl 。

       第四個是 proxy , 最好不要搭上本機作業系統 , -no-libproxy

複製程式碼
    -qt-pcre ............ Use the PCRE library bundled with Qt.                 
 +  -system-pcre ........ Use the PCRE library from the operating system.       
                                                                                
    -qt-xcb ............. Use xcb- libraries bundled with Qt.                   
                          (libxcb.so will still be used from operating system). 
 +  -system-xcb ......... Use xcb- libraries from the operating system.         
                                                                                
    -xkb-config-root .... Set default XKB config root. This option is used only together with -qt-xkbcommon-x11.
    -qt-xkbcommon-x11 ... Use the xkbcommon library bundled with Qt in combination with xcb.
 +  -system-xkbcommon-x11 Use the xkbcommon library from the operating system in combination with xcb.
                                                                                
    -no-xkbcommon-evdev . Do not use X-less xkbcommon when compiling libinput support.
 *  -xkbcommon-evdev .... Use X-less xkbcommon when compiling libinput support. 
複製程式碼

        pcre 是一個c語言編寫的正則表示式庫,這裡的話可以不指定。

        xcb  這裡的話我指定的是qt-xcb

        xkb  這裡的話我沒去搭理他,

複製程式碼
    -no-xinput2 ......... Do not compile XInput2 support.                       
 *  -xinput2 ............ Compile XInput2 support.                              
                                                                                
    -no-xcb-xlib......... Do not compile Xcb-Xlib support.                      
 *  -xcb-xlib............ Compile Xcb-Xlib support.                             
                                                                                
    -no-glib ............ Do not compile Glib support.                          
 +  -glib ............... Compile Glib support.                                 
                                                                                
    -no-pulseaudio ...... Do not compile PulseAudio support.                    
 +  -pulseaudio ......... Compile PulseAudio support.                           
                                                                                
    -no-alsa ............ Do not compile ALSA support.                          
 +  -alsa ............... Compile ALSA support.                                 
                                                                                
    -no-gtkstyle ........ Do not compile GTK theme support.                     
 +  -gtkstyle ........... Compile GTK theme support.       
複製程式碼

        xinput2 是關乎多點觸控的, 現在我還沒有用到,所以我忽略了他。

        xcb-xlib 我也沒有去管他。

        glib 我是直接給了 -no-glib

        pulseaudio 這是關於聲音系統的。我給了是預設

        alsa  這是音訊子系統的支援。 也是預設就行了。

        gtkstype  GTK 主題支援,這個還是算了吧,我只求能移植成功,功能不要太炫。

下面是一些另外的選項了

複製程式碼
Additional options:                                                             
                                                                                
    -make <part> ....... Add part to the list of parts to be built at make time.
                         (defaults to: libs tools examples)                     
    -nomake <part> ..... Exclude part from the list of parts to be built.       
                                                                                
    -skip <module> ..... Exclude an entire module from the build.               
                                                                                
    -no-compile-examples ... Install only the sources of examples.              
                                                                                
    -no-gui ............ Don't build the Qt GUI module and dependencies.        
 +  -gui ............... Build the Qt GUI module and dependencies.              
                                                                                
    -no-widgets ........ Don't build the Qt Widgets module and dependencies.    
 +  -widgets ........... Build the Qt Widgets module and dependencies.          
複製程式碼

        第一個是讓你選擇要不要編譯某些另外的模組, 比如說libs , tools , examples .我現在是把所有的加上,因為移植進去了就可以直接用 examples裡面的程式執行看一下是否移植成功。

        第二項是 gui 支援,我直接加上吧。

        第三個 widgets 也是差不多,也是直接上了。

複製程式碼
    -R <string> ........ Add an explicit runtime library path to the Qt         
                         libraries.                                             
    -l <string> ........ Add an explicit library.                               
                                                                                
    -no-rpath .......... Do not use the library install path as a runtime       
                         library path. On Apple platforms, this implies using   
                         absolute install names (based in -libdir) for dynamic  
                         libraries and frameworks.                              
 +  -rpath ............. Link Qt libraries and executables using the library    
                         install path as a runtime library path. Equivalent     
                         to -R install_libpath                                  
                                                                                
    -continue .......... Continue as far as possible if an error occurs.        
                                                                                
    -verbose, -v ....... Print verbose information about each step of the       
                         configure process.                                     
                                                                                
    -silent ............ Reduce the build output so that warnings and errors    
                         can be seen more easily.                               
                                                                                
複製程式碼

        第一項是新增一個庫在Qt程式執行時,這個我不管我選預設。

        第二項是新增一個庫

        我一般給這個rpath 給預設值。

        -continue 是指定如果出現某個錯誤指令繼續的命令。

        -v 是指列印詳細的資訊關於每個配置程式。

        -silent 是指定減少輸出的資訊,這樣的話查詢錯誤就更容易。

複製程式碼
    -no-cups ........... Do not compile CUPS support.                           
 *  -cups .............. Compile CUPS support.                                  
                         Requires cups/cups.h and libcups.so.2.                 
                                                                                
    -no-iconv .......... Do not compile support for iconv(3).                   
 *  -iconv ............. Compile support for iconv(3).                          
                                                                                
    -no-evdev .......... Do not compile support for evdev.                      
 *  -evdev ............. Compile support for evdev.                             
                                                                                
    -no-tslib .......... Do not compile support for tslib.                      
 *  -tslib ............. Compile support for tslib.                             
                                                                                
    -no-icu ............ Do not compile support for ICU libraries.              
 +  -icu ............... Compile support for ICU libraries.                     
複製程式碼

        -cups  是列印管理的一個支援, 一般的話選擇預設就好。

        -iconv  這是文字編碼轉化功能,這個網上有些教程說應該去掉這個功能  所以選擇 -no-iconv, 目前還沒有試驗。

        -evdev  這個選擇預設就行。

        -tslib     這個是觸控式螢幕矯正的一個功能。這個還是要加上。

        -icu   這個選項還是選擇預設。

複製程式碼
    -no-linuxfb ........ Do not compile Linux Framebuffer support.              
 *  -linuxfb ........... Compile Linux Framebuffer support.                     


    -no-opengl .......... Do not support OpenGL.                                
    -opengl <api> ....... Enable OpenGL support                                 
                          With no parameter, this will attempt to auto-detect   
                          OpenGL ES 2.0 and higher, or regular desktop OpenGL.  
                          Use es2 for <api> to override auto-detection.         
複製程式碼

        這連個選項, 使用linuxfb 的支援已經忽略opengl 

        -linux     -no-opengl

複製程式碼
 1 #!/bin/sh                                                                       
 2                                                                                 
 3                                                                                 
 4 ./configure \                                                                   
 5         -prefix /home/desk/7109/qtsrc/qt-src \                                  
 6         -confirm-license \                                                      
 7         -opensource \                                                           
 8         -release  \                                                             
 9         -make libs \                                                            
10         -xplatform linux-arm \                                                  
11         -optimized-qmake \                                                      
12         -linuxfb    \                                                           
13         -pch \                                                                  
14         -qt-sql-sqlite \                                                        
15         -qt-libjpeg \                                                           
16         -qt-libpng \                                                            
17         -qt-zlib \                                                              
18         -tslib \                                                                
19         -no-opengl \                                                            
20         -no-sse2 \                                                              
21         -no-openssl \                                                           
22         -no-nis \                                                               
23         -no-cups \                                                              
24         -no-glib \                                                              
25         -no-dbus \                                                              
26         -no-xcb \                                                               
27         -no-xcursor -no-xfixes -no-xrandr -no-xrender \                         
28         -no-separate-debug-info \                                               
29         -make examples -nomake tools -nomake tests -no-iconv                    
30                                                                               
複製程式碼

然後, make -j4

sudo make install