前言
最近在學習Tiny4412下的Qt編程。第一步,首先得搭建好交叉開發調試環境。幾經折騰之后,總算基本完成。茲整理一下期間的筆記,發到博客上,作為總結。也希望我入過的坑,其他人避免再入 。
另外提一點(也是事后查網才了解到的),目前業界流行Yocto/OpenEmbedded框架,很多廠商使用這個框架來構建分發開發板的BSP(包括kernel,rootfs,toolchain、gdb、庫以及qt的庫等),用戶可以直接基於該BSP來搭建Qt交叉開發環境,從而免去自己搭建環境時所遇到的諸如依賴庫缺失、toolchain版本不匹配等問題,節約了不必要的時間成本。相關案例非常多,“參考資料2~5”里列了幾個例子(都未經驗證,僅供參考)。
不過,Tiny4412好像還沒有提供yocto的BSP,所以目前還沒法體驗,但Yocto估計是大趨勢,有空要學習一下。
一、實驗環境
1.1 虛擬機環境
a) Vmware版本:Vmware Workstation 12.5.7
b) Ubuntu版本:Ubuntu 16.04.4 LTS(我用的是百問網JZ2440資料光盤_20180516中的版本,地址是:http://wiki.100ask.org/Download,然后找到:002_JZ2440資料光盤_20180516(免費) )
c) 內核版本:4.13.0
d) gcc版本:5.4.0
e) toolchain版本:
arm-linux-gcc 4.3.2
1.2 開發板環境
1.2.1 硬件
開發板:友善之臂tiny4412,底板:Tiny4412/Super4412SDK 1611,核心板:Tiny4412 版本號1412
1.2.2 軟件
a) 內核版本(tiny4412光盤自帶): linux-3.5-20170221
b) 根文件系統(tiny4412光盤自帶): rootfs_qtopia_qt4-20160514
二、具體過程
2.1 編譯、安裝qte-4.8.5
注:tiny4412的光盤里有已經編譯好的target-qte-4.8.5-to-hostpc.tgz,但由於我的Ubuntu版本和友善在編譯target-qte-4.8.5-to-hostpc.tgz時所使用的Ubuntu版本不一樣,所以解壓后,無法直接在qt-creator中使用(在點擊build按鈕后會報:The Qt version is invalid. Could not determine the path to the binaries of the Qt installation, maybe the qmake path is wrong?),只能從頭開始編譯。
把arm-qte-4.8.5-20131207.tar.gz 拷貝到開發機里,然后在mobaXterm串口終端執行以下命令:
tar xzvf arm-qte-4.8.5-20131207.tar.gz
cd arm-qte-4.8.5
./build.sh
注:第一次執行./build.sh時,報錯:tslib functionality test failed。但重新執行./build.sh后,卻又沒再報這個錯。原因不明,待查。
2.2 下載、編譯、安裝gdb-7.10,然后編譯安裝gdbserver
為什么選擇這個版本?因為以前學韋東山嵌入式Linux培訓三期攝像頭監控項目時,曾經用gdb-7.10成功搭建過遠程調試開發板的環境(其實那時選擇7.10版本也是有點憑感覺
)。
2.2.1 下載、編譯、安裝gdb-7.10(下載地址:http://ftp.gnu.org/gnu/gdb/gdb-7.10.tar.gz)
把gdb-7.10.tar.gz下載到開發機里(假設下載到/home/book/Downloads/),然后在mobaXterm串口終端執行以下命令:
tar xzvf gdb-7.10.tar.gz
cd /home/book/Downloads/gdb-7.10
mkdir build && cd build
../configure --target=arm-linux --prefix=/usr/local/arm-gdb-7.10 --with-python
注:可能還要加:--with-expat --includedir=/home/book/Downloads/expat-2.2.9/bin/include --libdir=/home/book/Downloads/expat-2.2.9/bin/lib,詳見下文注釋
make
make install
export PATH=$PATH:/usr/local/arm-gdb-7.10
(可以把這句話添加到/etc/environment或者~./bashrc,以保存對$PATH環境變量的修改)
| 注1:在對gdb-7.10進行configure時,要加入 --with-python選項(可能還要先下載安裝python2.7-dev),否則在qt-creator里啟動調試時,可能會報錯: 注2:如果configure加入--with-python選項后,報: checking for python2.7... no configure: error: python is missing or unusable 解決辦法是:先下載安裝python2.7-dev:apt-get install python2.7-dev,安裝完成后,可以執行 dpkg -l | grep python2.7-dev來驗證是否安裝成功 注3:編譯安裝完gdb-7.10后,如果在qt-creator里啟動調試時,在Application Output里報錯:warning: Can not parse XML target description; XML support ./configure --prefix=$PWD/bin mkdir bin make && make install 然后重新編譯、安裝gdb-7.10(在configure時,還要加入以下選項:--with-expat --includedir=/home/book/Downloads/expat-2.2.9/bin/include 注4:如果接下來執行make時報錯: checking for libexpat... (cached) no configure: error: expat is missing or unusable 解決辦法是:刪除gdb-7.10整個文件夾,然后重新解壓gdb-7.10.tar.gz,編譯、安裝。 原因是: 為了加快速度,configure會把上次的檢查結果作為一個cache變量(名字是ac_cv_libexpat)緩存到gdb/configure.cache中,而本次configure時,會先從 這個文件中查該cache變量,如果找不到,才會真正去檢查libexpat這個庫是否存在。所以,應該清除這個cache文件,強制configure去執行真正的檢查。 |
2.2.2 編譯、安裝gdbserver
在mobaXterm串口終端執行以下命令:
cd /home/book/Downloads/gdb-7.10/gdb/gdbserver
mkdir build && cd build
../configure --target=arm-linux -host=arm-linux
make CC=arm-linux-gcc
完成之后,會在build目錄下生成gdbserver可執行文件。把它拷貝到開發板的/usr/bin里(可以用ftp或者nfs,過程略):
2.3 把根文件系統拷貝解壓到開發機上
把Tiny4412隨機光盤中的rootfs_qtopia_qt4-20160514.tgz拷到開發機上(假設拷貝到/home/book/Downloads/friendly_arm/tiny4412/linux_rootfs/),然后執行:
tar xzvf rootfs_qtopia_qt4-20160514.tgz
2.4 下載、安裝Qt-5.9.0(下載地址:https://download.qt.io/archive/qt/5.9/5.9.0/qt-opensource-linux-x64-5.9.0.run)
為什么選擇這個版本?因為網上有很多成功案例,用這個版本搭建了交叉調試平台,有經驗可借鑒。
把qt-opensource-linux-x64-5.9.0.run下載到開發機里,然后在mobaXterm串口終端執行以下命令:
chmod +x qt-opensource-linux-x64-5.9.0.run
./qt-opensource-linux-x64-5.9.0.run
然后按照安裝向導的提示,一步步做即可(注:在“選擇組件”這一步,把Qt5.9.0下面的所有組件都選上,保險起見)
2.5 打開qt-creator,進入Tools==>Options進行配置
2.5.1 添加device
2.5.2 添加Qt version
2.5.3 添加compiler
2.5.4 添加debugger
2.5.5 添加kit
2.5.6 添加環境變量,以支持觸摸屏操作
方法1)修改開發板上的/etc/profile,(仿照/bin/setqt4env的內容)添加以下環境變量:
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export QWS_DISPLAY=:1
export QWS_KEYBOARD=TTY:/dev/tty1
export QWS_MOUSE_PROTO="Tslib MouseMan:/dev/input/mice"
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=/etc/ts-mt.conf
export TSLIB_PLUGINDIR=/usr/lib/ts
export TSLIB_TSDEVICE=/dev/touchscreen-1wire
方法2)在開發機的qt-creator里,進入project==>Build&Run==>tiny4412==>Run==>Base environment for this run configuration,添加上述環境變量:
2.5.7 修改開發板上的/usr/local/etc/sshd_config,以解決debug時報:“SFTP initialization failed: Server could not start SFTP subsystem”的問題
Subsystem sftp /usr/libexec/sftp-server
改為:
Subsystem sftp /usr/local/libexec/sftp-server
2.6 qt-creator新建一個widget測試程序test,然后做一些配置
2.6.1 修改“test.pro”文件,加入以下兩行:
target.path = /opt #為程序指定在開發板上的安裝路徑
INSTALLS += target
2.6.2 進入Project==>Build&Run==>Tiny4412==>Run Settings
至此,Tiny4412的Qt開發調試環境總算搭建完成,效果圖如下:
1)啟動調試:
2)停止調試:
三、參考資料
1)《Tiny4412用戶手冊》
2)QtCreator+Arm開發和聯機調試
3)imx6開發環境搭建之yocto全記錄(L4.1.15_2.0.0)















