linux 下安裝編譯配置 QT

注:html

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

還需要 apt-get install libxrandr-dev ,不然會有如下的報錯,designer 界面亂碼:windows

 

libxrandr-devbash

 

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
post


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

軟件環境


Linux:Ubuntu 12.04 X86ui

QT:4.8.4this

關於QT安裝


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

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

二、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

三、這就是本文用的方法,就是下載源代碼包,本身編譯安裝,最爲麻煩。但是原本就是學習的,何況現在僅僅能下載到源代碼包,那就先學習這個方案把。

軟件下載


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

一、首先是諾基亞的官方站點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

二、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的編譯與安裝


一、複製文件到本身想要的文件夾,解壓:

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

二、進入解壓後文件文件夾。運行配置

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

 

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

相關文章
相關標籤/搜索