Qt學習(如何交叉編譯一個Qt程序使其能在板子上運行) .

 如何交叉編譯一個Qt程序使其能在板子上運行

      首先安裝交叉編譯器arm-linux-gcc3.4.6,先將其壓縮包放到一個目錄下,然後對其進行解壓,舉了解壓命令爲:tar xjvf arm-linux-gcc-3.4.6-glibc-2.3.6.tar.bz2 -C /usr/local/(注意:C 後面有個空格,並且 C 是大寫的,它是英文單詞“Change”的第一個字母,在此是改變目錄的意思。這樣我們就將編譯器安裝在了/usr/local/gcc-3.4.6-glibc-2.3.6/arm-linux/下,然後設置環境變量,仍然是:gedit ~/.profile 在文件最後添加:export PATH=$PATH:/usr/local/gcc-3.4.6-glibc-2.3.6/arm-linux/bin,保存文件,然後執行:source ~/.profile是變量立即生效,然後在命令行下輸入:arm-linux-gcc -v檢查是否安裝成功,安裝成功則出現:Reading specs from /usr/local/gcc-3.4.6-glibc-2.3.6/arm-linux/bin/../lib/gcc/arm-linux/3.4.6/specs
Configured with: /home/samba/armlinux/crosstool/crosstool-0.42/build/arm-linux/gcc-3.4.6-glibc-2.3.6/gcc-3.4.6/configure --target=arm-linux --host=i686-host_pc-linux-gnu --prefix=/opt/crosstool/gcc-3.4.6-glibc-2.3.6/arm-linux --with-headers=/opt/crosstool/gcc-3.4.6-glibc-2.3.6/arm-linux/arm-linux/include --with-local-prefix=/opt/crosstool/gcc-3.4.6-glibc-2.3.6/arm-linux/arm-linux --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
Thread model: posix
gcc version 3.4.6
否則可能是環境變量設置問題,仔細檢查應該就能解決。

交叉編譯工具安裝好後開始用其交叉編譯qte4.6.3-arm,

下面開始編譯安裝qte4.6.3-arm,首先到官方下載最新版的qte,版本爲:qt-everywhere-opensource-src-4.6.3.tar.gz ,下載地址爲:http://qt.nokia.com/downloads/embedded-linux-cpp,然後開始編譯安裝,
具體步驟如下:進入文件所在目錄:cd /root/song,解壓:tar xzvf qt-everywhere-opensource-src-4.6.3.tar.gz,進入解壓目錄:cd qt-everywhere-opensource-src-4.6.3,修改錯誤文件:gedit src/3rdparty/freetype/include/freetype/config/ftconfig.h,將第330行修改爲:"orr    %0, %0,%2, lsl #16\n\t"  /* %0 |= %2 << 16 */,防止出現如下錯誤:text/qfontengine_ft.cpp: In member function `bool QFontEngineFT::init(QFontEngine::FaceId, bool, QFontEngineFT::GlyphFormat)':
text/qfontengine_ft.cpp:696: warning: converting to `int' from `qreal'
{standard input}: Assembler messages:
{standard input}:781: Error: register or shift expression expected -- `orr r3,r2,lsl#16'
{standard input}:792: Error: register or shift expression expected -- `orr r2,r3,lsl#16'
{standard input}:7752: Error: register or shift expression expected -- `orr r3,r0,lsl#16'
{standard input}:7765: Error: register or shift expression expected -- `orr r1,r0,lsl#16'
make[1]: *** [.obj/release-shared-emb-arm/qfontengine_ft.o] 錯誤 1
make[1]:正在離開目錄 `/root/song/qt-everywhere-opensource-src-4.6.3;然後開始配置configure:命令爲:./configure -qt-kbd-tty -qt-gfx-linuxfb -no-gfx-transformed -no-gfx-multiscreen -qt-mouse-pc -no-gfx-qvfb -no-gfx-vnc -qt-kbd-tty -qt-gfx-linuxfb -no-gfx-qvfb -no-gfx-vnc -qt-mouse-tslib -no-glib -prefix /usr/local/Trolltech/qte4.7.2-arm -embedded arm -release -shared -fast -no-largefile -qt-sql-sqlite -no-qt3support -no-xmlpatterns -no-mmx -no-3dnow -no-sse -no-sse2 -no-svg -no-webkit -qt-zlib -qt-gif -qt-libtiff -qt-libpng -qt-libmng -qt-libjpeg -make libs -nomake tools -nomake examples -nomake docs -nomake demo -no-nis -no-cups -no-iconv -no-dbus -no-openssl -xplatform qws/linux-arm-g++ -little-endian -qt-freetype -depths 16,18 -I/usr/local/tslib/include -L/usr/local/tslib/lib -v -D__ARM_ARCH_5TEJ__,然後輸入o回車,再輸入yes回車開始配置,配置成功提示:Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into /usr/local/qte4.6.3-arm

To reconfigure, run 'make confclean' and 'configure'.
然後開始編譯:make,需要等待一會,快慢視個人配置。大概半個小時左右make完畢,然後執行:make install,完成後qte就被安裝在了/usr/local/qte4.6.3-arm下面,至此,qte4.6.3-arm編譯安裝成功。

下面我們就行交叉編譯一個程序使其能在板子上運行,用交叉編譯器arm-linux-gcc配置編譯過的qte4.6.3,使用其下面的qmake工具區編譯程序。首先要進入到要編譯程序的目錄下,在找到交叉編譯過的qte下的qmake工具運行命令例如:/usr/local/qte/bin/qmake 運行之後會出現已個Makefile文件(當你打開此文件裏面會又有說明其使用arm-linux-gcc交叉編譯工具的說明,如果在pc機下安裝的Qt編寫程序時會出現Makefile文件當你打開時他會說明使用的是gcc編譯器),然後make一下會生成一個可執行文件,此時的程序可以在板子上直接運行了(你的板子上必須有Qte的相關庫)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章