QTE移植过程及问题

来源:互联网 发布:造价软件 编辑:程序博客网 时间:2024/04/29 02:59
qt/embedded 4.5.3 的编译与移植~
 
README:
qt/embedded 4.5.3 的编译,视你的编译器的不同可以编译出两种版本:
一、用以主机下(即x86)下的版本,配合qvfb(编译看下一篇日志 ),可以在主机上模仿在目标板上的运行过程;
二、用于目标板(即ARM)上的版本,在目标板上下运行qt程序需要用它的qmake,下载编译出来的lib目录,lib里包括一些库和fonts;
三、按此文档需在理解的基础上成功移植;

课外知识:
首先,有必要区分几个名词:Qt,Qt/E,Qtopia Core, Qtopia。(引用自Qt中文论坛)

Qt泛指Qt的所有桌面版本,比如Qt/X11,Qt Windows,Qt Mac等。由于Qt最早是在Linux中随着KDE流行开来的,因此通常很多人说的Qt都指用于Linux/Unix的Qt/X11。

Qt/E(Qt/Embedded)是用于嵌入式Linux系统的Qt版本。Qt/E去掉了X Lib的依赖而直接工作于Frame Buffer上,因而效率更高,但它并不是Qt的子集,而应该是超集,部分机制(如QCOP等)不能用于Qt/X11中。

Qtopia是一个构建于Qt/E之上的类似桌面系统的应用环境。相比之下,Qt/E是基础类库。

Qtopia Core:就是原来的Qt/E,大概从Qt 4开始改名,把Qtopia Core并到Qtopia的产品线中去了。但实际上Qtopia Core就相当于原来的Qt/E,仍然作为基础类库。

另外,似乎奇趣最近又把Qtopia Core改名叫做Qt for Embedded Linux了,不知道是不是因为Qtopia Core搞得大家都很糊涂,没人来买的缘故。

下面开始编译:
1、系统环境以及准备文件
主机操作系统:Ubuntu 8.04
主机编译器:gcc 版本 4.2
交叉编译器:arm-linux-gcc 3.4.1 (后来下载了个4.3.2,自己都不知道用的是哪个了,后来的库用的是3.4.1,觉的用的应该是这个)
软件安装包:(软件包事先下载到了主目录下的Qt目录)
qt-embedded-linux-opensource-src-4.5.3.tar.gz
tslib-1.4.tar.gz
Qt的软件安装包可以到http://ftp3.ie.freebsd.org/pub/trolltech/pub/qt/source/下载,tslib的安装包请自行搜索

2、编译安装qt-embedded到/usr/local/qte-x86和/usr/local/qte-arm(进入到Qt目录)

为了程序开发的便捷性,安装了x86版和arm版,先在PC上使用x86版和qvfb开发,完成以后再使用arm版交叉编译放到开发版上运行。

A、解压qt-embedded-linux-opensource-src-4.5.3.tar.gz
把源文件qt-embedded-linux-opensource-src-4.5.3.tar.gz解压到当前目录下。执行:

tar xvzf qt-embedded-linux-opensource-src-4.5.3.tar.gz
将其解压得到qt-embedded-linux-opensource-src-4.5.3目录,重命名为qte-x86。
再次解压qt-embedded-linux-opensource-src-4.5.3.tar.gz,并重命名为qte-arm。
在qte-x86目录下编译x86架构的编译工具链,用于PC机上的仿真调试。在qte-arm目录下编译arm架构的编译工具链,用于交叉编译在arm开发板上运行的程序。

B、编译安装触摸屏库软件tslib-1.4.tar.gz
解压tslib-1.4.tar.gz文件到当前目录,进入到解压后的tslib-1.4目录。运行:

./autogen.sh
./configure --prefix=/usr/local/qte-arm/tslib-1.4 --host=arm-linux ac_cv_func_malloc_0_nonnull=yes
make
sudo make install

这样就可以在/usr/local/qte-arm/tslib-1.4目录下看到相关的应用程序、共享库、配置文件等。

C、编译安装qte-x86(进入到qte-x86目录)

./configure -prefix /usr/local/qte-x86 /
> -no-qt3support /
> -system-zlib /
> -system-libtiff /
> -system-libpng /
> -system-libjpeg /
> -qt-libmng /
> -make libs /
> -make examples / (注:因为这个是x86版本,是在PC上仿真的,所以编译这个为了演示,下同)
> -make demos /
> -no-nis /
> -no-cups /
> -no-iconv /
> -xplatform qws/linux-x86-g++ /
> -embedded x86 /
> -depths 16,24,32 /
> -qt-gfx-qvfb /
> -no-gfx-linuxfb /
> -no-gfx-transformed /
> -no-gfx-vnc /
> -no-gfx-multiscreen /
> -qt-kbd-tty /
> -qt-kbd-usb /
> -qt-mouse-pc /
> -no-glib
make
sudo make install
编译出来X86下的EMBEDDED作用是可以在主机上使用qvfb模拟在目标板上的运行情况;而编译出来的arm下的是不可的~
一些默认的选项就没有必要再列出来了,除非需要的功能刚好和默认的相反。

D、编译安装qte-arm (进入到qte-arm目录)

./configure -prefix /usr/local/qte-arm /
> -no-qt3support /
> -qt-zlib /
> -qt-libtiff /
> -qt-libpng /
> -qt-libmng /
> -qt-libjpeg /
> -make libs /
> -nomake examples / (因为这个是arm版本,所以编译出来的程序只能在arm开发板上运行,编译时把这些给去掉,加快编译过程)
> -make demos / (用以测试)
> -nomake docs /
> -no-nis /
> -no-cups /
> -no-iconv /
> -xplatform qws/linux-arm-g++ /
> -embedded arm /
> -little-endian /
> -qt-freetype /
> -depths 8,16,24,32 /
> -qt-gfx-linuxfb /
> -no-gfx-transformed /
> -no-gfx-qvfb /
> -no-gfx-vnc /
> -no-gfx-multiscreen /
> -qt-kbd-usb /
> -qt-kbd-tty /
> -qt-mouse-pc /
> -no-glib /
> -qt-mouse-tslib -I/usr/local/qte-arm/tslib-1.4/include -L/usr/local/qte-arm/tslib-1.4/lib
make
sudo make install

编译选项-qt-mouse-tslib需要用到触摸屏功能的动态库,所以得把之前编译安装的tslib库包含进来。
至此,Qt/E的编译安装工作算是完成了,把这两个都编译好所花时间4个多小时,还真是一个漫长的过程啊。

为了方便以后使用,俺把它们打包备份了。为了方便备份,所以我才把tslib的安装目录放到了qte-arm下,因为在编译应用于arm开发板的程序时总是需要链接tslib库的。所以使用下面的命令打包后,以后需要使用时直接解压就可以而不必担心缺失tslib库。

tar cvzf qte-arm.tar.gz -P /usr/local/qte-arm 解压命令 tar xvzf qte-arm.tar.gz -C /

把/usr/local/qt-x86/bin目录下的qvfb工具复制到/usr/local/qte-x86/bin目录下,然后打包备份。

sudo cp /usr/local/qt-x86/bin/qvfb* /usr/local/qte-x86/bin/
tar cvzf qte-x86.tar.gz -P /usr/local/qte-x86 解压命令 tar xvzf qte-x86.tar.gz -C /

为了方便使用qte-x86和qte-arm工具链来编译程序,必要的环境变量还是得设置一下的。其实,在编译Qt程序时,我们一般只是使用到了qmake工具,所以只要在~/.bashrc中添加几个alias就可以了。

cat >> ~/.bashrc <<EOF
alias qvfb='/usr/local/qte-x86/bin/qvfb -width 640 -height 480'
alias qte-x86-make='/usr/local/qte-x86/bin/qmake'
alias qte-arm-make='/usr/local/qte-arm/bin/qmake'
EOF
source ~/.bashrc 或 . ~/.bashrc

3、qte-arm 的移植和配置


首先要先移植tslib,看上一篇日志!

将编译出来的  /usr/local/qte-arm /lib 打包下载(可以把链接一同下载)到目标板上

设置好环境变量:
export T_ROOT=.../tslib-1.4
export PATH=/$T_ROOT/bin:/$PATH
export LD_LIBRARY_PATH=/$T_ROOT/lib:/(编译出来的arm的路径)lib
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_PLUGINDIR=/$T_ROOT/lib/ts
export TSLIB_CONFFILE=/$T_ROOT/etc/ts.conf
export TSLIB_CALIBFILE=/etc/pointercal
export QWS_KEYBOARD=USB:/dev/input/event1
export QWS_MOUSE_PROTO=Tslib:/dev/input/event0
export QWS_DISPLAY=LinuxFb:mmWidth45:mmHeight60:0
export QWS_SIZE=640x480
export QT_QWS_FONTDIR=/path to your font dir
export POINTERCAL_FILE=/mnt/yaffs/pointercal

到主机上demos里面,找到一个测试程序a编译:

编译前先设置环境变量:
export QTDIR=//usr/local/qte-arm
export T_ROOT=/tslib-1.4
export PATH=/$T_ROOT/bin:/$PATH
export LD_LIBRARY_PATH=/$T_ROOT/lib:/$QTDIR/lib
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_PLUGINDIR=/$T_ROOT/lib/ts
export TSLIB_CONFFILE=/$T_ROOT/etc/ts.conf
export TSLIB_CALIBFILE=/etc/pointercal
export QWS_KEYBOARD=USB:/dev/input/event1
export QWS_MOUSE_PROTO=Tslib:/dev/input/event0
export QWS_DISPLAY=LinuxFb:mmWidth45:mmHeight60:0
export QWS_SIZE=640x480
export QT_QWS_FONTDIR=/path to your font dir

qmake a.pro  生成makefile;

make

将make出来的文件下载到目标板;

目标板上建立文件夹 /mny/yaffs/Qtopia/tmp,否则会出现错误;

./a   执行;

大功告成!

可能出现的问题:
0/
linux下配置QT QMAKESPEC has not been set, so configuration cannot be deduced

如果编译时候出现错误:QMAKESPEC has not been set, so configuration cannot be deduced.

Error processing project file: XXXXX.pro

是QMAKESPEC变量没有设置好,可以在/root/.bash_profile里加入一行:

export QMAKESPEC=/usr/local/qt-x11-opensource-src-4.3.2/mkspecs/qws/linux-arm-g++(即是linux-arm-g++的路径)

1/
error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory

2/
[root@FriendlyARM fa]# ./hello
./hello: error while loading shared libraries: librt.so.1: cannot open shared object file: No such file or directory

3/
[root@FriendlyARM fa]# ./hello
QWSSocket::connectToLocalFile could not connect:: No such file or directory
QWSSocket::connectToLocalFile could not connect:: No such file or directory
QWSSocket::connectToLocalFile could not connect:: No such file or directory
QWSSocket::connectToLocalFile could not connect:: No such file or directory
QWSSocket::connectToLocalFile could not connect:: No such file or directory
QWSSocket::connectToLocalFile could not connect:: No such file or directory
No Qt for Embedded Linux server appears to be running.
If you want to run this program as a server,
add the "-qws" command-line option.

4/
[root@FriendlyARM fa]# ./hello -qws
QFontDatabase: Cannot find font directory /usr/local/qte-arm/lib/fonts - is Qt ?
Aborted
(注:/usr/local/qte-arm/lib/fonts这个具体路径视你安装qte-arm的路径而定)

5/
[root@FriendlyARM fa]# ./hello -qws
./hello: relocation error: /opt/qt/lib/libQtGui.so.4: symbol __floatsisf, version Gcc_3.0 not defined in file libgcc_s.so.1 with link time reference.

如果你严格按照前面的几个步骤执行了,那么前四个问题是不会出现的了。第5个问题的解决:拷贝/usr/local/arm/3.4.1/arm- linux/lib/目录下的libgcc_s.so、libgcc_s.so.1(你用的是什么编译器,你就要在这个编译器下的lib里面复制)这两个文件覆盖/opt/FriendlyARM/mini2440 /root_nfs/lib目录下的libgcc_s.so、libgcc_s.so.1就可以了(其实这两个文件中,一个是另外一个的符号链接)。(参 考移植QT4.5.0到博创UP-NETARM2410-S平台的网友评论部分)

6/
错误提示:Cannot create Qtopia Core data directory: /tmp/qtembedded-0
解决办法:建立文件夹 /mnt/yaffs/Qtopia/tmp 
原因:博创给的内核把/tmp链接到了
/mnt/yaffs/Qtopia/tmp,其他板可能不同

7/
错误提示:
" /bin/ld: ERROR: Source object XXX has EABI version 0, but target XXXX has EABI version 4 "
解决办法:更换交叉编译工具
原因:你在编译qt/embedded的时候和编译程序用的不是同一个交叉编译工具,交叉编译工具从4.0后的版本开始支持EABI标准,这个时候需要更改你的交叉编译工具

8/
错误提示:Qt经典出错信息之QFontDatabase: Cannot find font directory
解决方法:export QT_QWS_FONTDIR=/path/to/your/font/dir

9/
错误提示:bus error
解决方法:内存满了,删除一些东西,如果你的也所s3c2410,那么你就只能外部挂载了,用U盘挂载或者NFS,要不然是不够用的

10/
错误提示:Unable to generate makefile for: /usr/lib/qt4/examples/dialogs/tabdialog/tabdialog.pro
解放方法:修改文件的权限为所有用户:
a.看目录的所有权
ls -lh /home/applee/qt/examples
drwxr-xr-x 3 root root 4.0K 2010-03-23 21:20 assistant
drwxr-xr-x 7 root root 4.0K 2010-03-23 21:20 dbus
drwxr-xr-x 9 root root 4.0K 2010-03-23 21:20 designer
drwxr-xr-x 4 root root 4.0K 2010-03-23 21:20 desktop

b.果然都是所属root组root用户的,于是修改了下
sudo chown -R  applee  /home/applee/qt/examples
c.这时再用我的用户编译那些examples都没问题了

11/
错误提示:
解决:export POINTERCAL_FILE=/mnt/yaffs/pointercal到你的文件目录,这个文件会自动生成

12/
error:QWSTslibMouseHandlerPrivate: ts_open() failed with error: 'No such file or dire'
solve: Please check your tslib installation!

add:export QWS_MOUSE_PROTO=tslib:/dev/event0