linux 下安裝編譯配置 QT


注:

1,自己 make qt-everywhere-opensource-src s時,在./configure前主動裝好以下3個
sudo apt-get install libX11-dev libXext-dev libXtst-dev\

還須要 apt-get install libxrandr-dev ,否則會有以下的報錯,designer 界面亂碼:

 

libxrandr-dev

 

X Error: BadDrawable (invalid Pixmap or Window parameter) 9
  Major opcode: 62 (X_CopyArea)
  Resource id:  0x0

2, 在/etc/profile 中加入 環境變量
export QTDIR=/usr/local/Trolltech/Qt-4.8.6                                                                                                                                                              
 export PATH=$QTDIR/bin:$PATH  
 export MANPATH=$QTDIR/man:$MANPATH  
 export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH


打算做嵌入式圖像處理。計划方案嵌入式Linux+OpenCV+QT。昨天簡單入門OpenCV今天看看QT,QT就先弄Linux以下的,回家之前爭取把主要的摸通。然后能在板子上跑起來。

軟件環境


Linux:Ubuntu 12.04 X86

QT:4.8.4

關於QT安裝


QT的早期版本號和如今版本號有點變化。提供的文件也不盡相同,最新的版本號為5.0,我這里用的是4.8.4,一個完整的QT應該包含QT庫、IDE也就是QT creator。在Linux下的安裝中,眼下看到的主要有三種方法:

1、.bin文件直接安裝。文件名稱為qt-sdk-……。一個./bin直接包含了全部相關工具。安裝起來最為簡單方便,可是眼下的4.8.4在幾個站點上已經找不到總的sdk的bin文件了,老版本號的還是能夠的。

2、Ubuntu下使用atp-get安裝,方法例如以下(未驗證)

sudo apt-get install qt4-dev-tools #開發包   
sudo apt-get install qtcreator #IDE  
sudo apt-get install qt4-doc #開發幫助文檔   
sudo apt-get install qt4-qtconfig #配置工具   
sudo apt-get install qt4-demos #DEMO源代碼  QT

3、這就是本文用的方法,就是下載源代碼包,自己編譯安裝,最為麻煩。可是本來就是學習的,況且如今僅僅能下載到源代碼包,那就先學習這個方案把。

軟件下載


QT有好幾個下載站點,這里匯總介紹。自從諾基亞公司放棄Meego、遣散Qt開發團隊以后。Qt商業版本號的站點移到了qt.digia.com。而開源版本號則放到了qt-project.org  :

1、首先是諾基亞的官方站點http://qt.digia.com/  這個是不太方便的,想高速下載的接着看后面的。

此站點須要填寫username和郵箱地址,下載地址會發送到郵件里,我就把我收到的地址貼出來吧。以下是郵件中的地址匯總。

這里面的linux源代碼是commercial版本號。

Qt 4.8.4 for embedded Linux

http://dist.qt.digia.com/developer/download/qt-everywhere-commercial-src-4.8.4.tar.gz

Installing Qt for embedded Linux

http://qt-project.org/doc/qt-4.8/qt-embedded-install.html

Qt Commercial Charts 1.1.0

http://dist.qt.digia.com/developer/download_charts/qt-commercial-charts-src-1.1.0.tar.gz

Qt 5.0.0 Sources

http://dist.qt.digia.com/developer/download_50/qt-everywhere-commercial-src-5.0.0.tar.gz

Qt 4.8.4 for Windows (Src and VS2008 32bit Binary)

http://dist.qt.digia.com/developer/download/qt-win-commercial-4.8.4-vs2008.exe

Qt Visual Studio Addin 1.1.11 for Qt4 (Binary)

http://dist.qt.digia.com/developer/download/qt-vs-addin-1.1.11.exe

Qt 4.8.4 for Windows (Src and VS2010 32bit Binary)

http://dist.qt.digia.com/developer/download/qt-win-commercial-4.8.4-vs2010.exe

Qt 4.8.4 for Windows (Src and MinGW 32bit Binary)

http://dist.qt.digia.com/developer/download/qt-win-commercial-4.8.4-mingw.exe

Qt Creator 2.6.1 for Windows (32bit Binary)

http://dist.qt.digia.com/developer/download_creator/qt-creator-win-commercial-2.6.1.exe

Qt 4.8.4 for Windows (Src and VS2010 64bit Binary)

http://dist.qt.digia.com/developer/download/qt-win-commercial-4.8.4-vs2010-64bit.exe

Qt Commercial Charts 1.1.0

http://dist.qt.digia.com/developer/download_charts/qt-commercial-charts-src-1.1.0.zip

Qt 5.0.0 Sources

http://dist.qt.digia.com/developer/download_50/qt-everywhere-commercial-src-5.0.0.zip

Qt 5.0.0 Offline SDK for Windows (32-bit Binary)

http://dist.qt.digia.com/developer/download_50/qt-windows-commercial-5.0.0-msvc2010_32-x86-offline.exe

Qt Visual Studio Addin 1.2.0 for Qt5 (Binary)

http://dist.qt.digia.com/developer/download_50/qt-vs-addin-1.2.0.exe

2、QT-project站點下載 http://qt-project.org/downloads

這個站點就直接並且清楚多了,分類非常清楚,例如以下圖所看到的。

image

須要說明的是Qt libraries 4.8.4 for embedded Linux (236 MB) 下載鏈接和Qt libraries 4.8.4 for Linux/X11 (225 MB) 事實上下載的是一個東西,反正我看到的鏈接地址都是一樣的,這也就是Linux下我們須要用的。另外從這個頁面再下載開發所用的IDE QT Creator,這是一個bin文件,能夠直接安裝。

QT的編譯與安裝


1、復制文件到自己想要的文件夾,解壓:

tar zxvf qt-everywhere-opensource-src-4.8.4.tar.gz

2、進入解壓后文件文件夾。運行配置

root@emouse:~/study# cd qt-everywhere-opensource-src-4.8.4/

root@emouse:~/study/qt-everywhere-opensource-src-4.8.4# ./configure

此處也能夠加上配置前綴./configure -prefix /opt/qt-4.8.4-x11

這種話再后面編譯過程中的文件會拷貝到/opt/qt-4.8.4-x11 這個文件夾下(文件夾不存在會自己主動創建),優點是源代碼便於管理,

關於這部分前綴配置能夠我在config文件里找到這部分代碼,能夠參考。能夠從這段代碼中看出對應的配置以及沒有配置的情況下默認安裝文件夾。代碼位於3594行。例如以下:

復制代碼
#-------------------------------------------------------------------------------
# post process QT_INSTALL_* variables
#-------------------------------------------------------------------------------

#prefix
if [ -z "$QT_INSTALL_PREFIX" ]; then
    if [ "$CFG_DEV" = "yes" ]; then
        QT_INSTALL_PREFIX="$outpath" # In Development, we use sandboxed builds by default
    elif [ "$PLATFORM_QWS" = "yes" -o "$PLATFORM_QPA" = "yes" ]; then
        if [ "$PLATFORM_QPA" = "yes" ]; then
    QT_INSTALL_PREFIX="/usr/local/Trolltech/QtLighthouse-${QT_VERSION}"
        else
    QT_INSTALL_PREFIX="/usr/local/Trolltech/QtEmbedded-${QT_VERSION}"
        fi
        if [ "$PLATFORM" != "$XPLATFORM" ]; then
            QT_INSTALL_PREFIX="${QT_INSTALL_PREFIX}-${CFG_ARCH}"
        fi
    elif [ -d "$EPOCROOT" ] && [ "$XPLATFORM_SYMBIAN" = "yes" ]; then
        if [ "$XPLATFORM_SYMBIAN" = "yes" ]; then
            QT_INSTALL_PREFIX="$EPOCROOT/epoc32/"
            QT_INSTALL_LIBS="$EPOCROOT/epoc32/release/armv5/lib/"
        fi
    else
        QT_INSTALL_PREFIX="/usr/local/Trolltech/Qt-${QT_VERSION}" # the default install prefix is /usr/local/Trolltech/Qt-$QT_VERSION
復制代碼

配置過程中會有以下提示:

Which edition of Qt do you want to use ?

Type 'c' if you want to use the Commercial Edition.
Type 'o' if you want to use the Open Source Edition.

當然選擇o啦。繼續提示:

復制代碼
This is the  Open Source Edition.

You are licensed to use this software under the terms of
the Lesser GNU General Public License (LGPL) versions 2.1.
You are also licensed to use this software under the terms of
the GNU General Public License (GPL) versions 3.

Type '3' to view the GNU 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。回車就可以。接下來就會生成makefile文件,配置過程十來分鍾左右。配置完畢后運行make。

接下來能夠吃個飯或者睡一覺,編譯時間大概3個小時左右,比較漫長,耐心等待吧。

經過漫長的等待之后,運行sudo make install來安裝。會安裝到/usr/local/Trolltech/Qt-4.8.4文件夾下。

安裝時間比較短。大概須要幾分鍾左右,至此。安裝完畢。

小測試一下,運行 /usr/local/Trolltech/Qt-4.8.4/bin/designer ,看見 qt 啟動,例如以下圖所看到的,就說明QT已經成功安裝。

image

其它配置


qmake這個命令須要進行環境變量的配置才干找到的到,我看了下我的系統里已經包含了這個命令了,僅僅是路徑不一樣。

測試例如以下:

root@emouse:/# qmake -v
Qmake version: 1.07a (Qt 3.3.8b)
Qmake is free software from Trolltech ASA.
root@emouse:/# which qmake
/usr/bin/qmake

在看一下qmake的屬性

image

從這個地方能夠看出qmake這個命令別鏈接到了/etc/alternatives/qmake,還是不清楚是啥地方來的命令,繼續看!

找到/etc/alternatives/qmake,在看一下屬性就清楚了。能夠看到這個地方又鏈接回去了。那么假設還使用qmake命令的話實際使用的是qmake-qt3,這樣就會出現錯誤。image也能夠使用以下命令高速查看:

root@emouse:/# ls /usr/bin/qmake -ln
lrwxrwxrwx 1 0 0 23 12月 14 21:06 /usr/bin/qmake -> /etc/alternatives/qmake
root@emouse:/# ls /etc/alternatives/qmake -ln
lrwxrwxrwx 1 0 0 18 12月 14 21:06 /etc/alternatives/qmake -> /usr/bin/qmake-qt3

通過以上的分析能夠知道,解決問題有兩種方法,一個就是更改qmake的鏈接,使得qmake這個命令鏈接到安裝文件夾下我們安裝版本號的qmake,另一種方法就是改環境變量。

先說更改鏈接的方法,通過上面的介紹,這個事實上操作就比較直接和簡單了,命令和實驗結果例如以下:

root@emouse:/# rm /etc/alternatives/qmake 
root@emouse:/# ln -s /usr/local/Trolltech/Qt-4.8.4/bin/qmake /etc/alternatives/qmake
root@emouse:/# qmake -v
QMake version 2.01a
Using Qt version 4.8.4 in /usr/local/Trolltech/Qt-4.8.4/lib

能夠看到,qmake已經成功更改為4.8.4版本號。

另外一種辦法就是更改環境變量,這個我沒有嘗試,有興趣的自己驗證。

vi /home/defonds/.bashrc 用來改動用戶環境變量,在文件后面加入以下信息

export QTDIR=/usr/local/Trolltech/Qt-4.8.4 
export PATH=$QTDIR/bin:$PATH  
export MANPATH=$QTDIR/man:$MANPATH  
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH

再改動全部用戶環境變量vi /etc/profile 相同在文件后加入上面的環境變量信息。這個方案應該相同可行。

Qt-creator的安裝與配置


依據上面提供的網址下載qt creator在linux下的安裝文件qt-creator-linux-x86-opensource-2.6.1.bin,以下的安裝就比較簡單了,首先更改文件屬性,使它可運行。

chmod u+x qt-creator-linux-x86-opensource-2.6.1.bin

然后運行sudo ./qt-creator-linux-x86-opensource-2.6.1.bin

接下來就是非常熟悉的安裝界面了。

image

安裝完畢就可以。

接下來就能夠使用這個IDE來進行開發了。這種界面是不是在linux下非常難得呢?

image

 

初步的安裝就到這里。下次繼續寫關於嵌入式開發平台的構建。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM