全部博文(198)
分类: LINUX
2012-03-15 14:45:48
一、编译本机QT环境:
宿主机:RH9
编译器:gcc 3.2.2
源码包:
工作目录:/root/x86QT
############ build x86 QT ###########################
设置环境变量:
cd x86QT
export QTEDIR=$PWD/qt-2.3.10
export QT2DIR=$PWD/qt-2.3.2
export TMAKEDIR=$PWD/tmake-1.13
1.1 编译qt-2.3.2包
cd $QT2DIR
export TMAKEPATH=$TMAKEDIR/lib/linux-g++
export QTDIR=$QT2DIR
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
./configure -no-xft
yes
make
至此本机的qt-2.3.2环境编译完成!
1.1.1编写HELLO程序测试该环境
################# test example hello(x86 qtlib) ##################
[root@BC x86QT]# mkdir exp
[root@BC x86QT]# cd exp/
[root@BC exp]# vi hello.cpp
//hello.cpp
#include
#include
int main(int argc, char **argv)
{
QApplication app (argc, argv);
QLabel *hello = new QLabel("Hello Qt/Embedded!", 0);
app.setMainWidget(hello);
hello->show();
return app.exec();
}
//end
[root@BC exp]# ls
hello.cpp
设置编译环境变量:
export TMAKEPATH=$TMAKEDIR/lib/linux-g++
export QTDIR=$QT2DIR
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
开始编译:
[root@BC exp]# $TMAKEDIR/bin/progen -t app.t -o hello.pro
[root@BC exp]# ls
hello.cpp hello.pro
查看相关变量:
[root@BC exp]# echo $TMAKEPATH
/root/x86QT/tmake-1.13/lib/linux-g++
[root@BC exp]# echo $QTDIR
/root/x86QT/qt-2.3.2
[root@BC exp]#$TMAKEDIR/bin/tmake -o Makefile hello.pro
[root@BC exp]#make
[root@BC exp]# ./hello
################## end hello ###############################
1.2 编译qt-2.3.10包
########## build qte lib for local env #####################
cd $QTEDIR
设置环境变量:
export TMAKEPATH=$TMAKEDIR/lib/qws/linux-x86-g++
export QTDIR=$QTEDIR
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
配置库:
./configure -no-xft -qvfb -depths 4,8,16,32
yes
5
编译:
make
1.2.1 编写HELLO测试该环境
################# test example hello(qtelib) ###############
[root@BC x86QT]# mkdir exp
[root@BC x86QT]# cd exp/
[root@BC exp]# vi hello.cpp
//hello.cpp
#include
#include
int main(int argc, char **argv)
{
QApplication app (argc, argv);
QLabel *hello = new QLabel("Hello Qt/Embedded!", 0);
app.setMainWidget(hello);
hello->show();
return app.exec();
}
//end
[root@BC exp]# ls
hello.cpp
[root@BC exp]# $TMAKEDIR/bin/progen -t app.t -o hello.pro
[root@BC exp]# ls
hello.cpp hello.pro
查看环境变量:
[root@BC exp]# echo $TMAKEPATH
/root/x86QT/tmake-1.13/lib/qws/linux-x86-g++
[root@BC exp]# echo $QTDIR
/root/x86QT/qt-2.3.10
[root@BC exp]#$TMAKEDIR/bin/tmake -o Makefile hello.pro
编译:
[root@BC exp]#make
启动QVFB
[root@BC exp]# qvfb &
执行
[root@BC exp]# ./hello
################## end hello ###############################
二、编译ARM版本QT/E库环境
宿主机:RH9 目标机:ARM
交叉编译器:arm-linux-gcc3.4.1
源码包:
工作目录:/root/arm2410QT
########## build qtelib env for arm ########################
cd /root/arm2410QT
设置环境变量:
export QTEDIR=$PWD/qt-2.3.10
export TMAKEDIR=$PWD/tmake-1.13
export TSLIBDIR=$PWD/tslib
export TSLIBINST=$PWD/tslib-install
export LD_LIBRARY_PATH=$TSLIBINST/lib
export CC=arm-linux-gcc
2.1 编译触摸屏库:
cd tslib
./autogen.sh --host=arm-linux --prefix=$TSLIBINST
make clean
make -j4
make install
拷贝触摸屏库到QTE库目录:
#####cp tslib to qte lib dir
cp -a $TSLIBDIR/src/.libs/* $QTEDIR/lib/
cp -a $TSLIBDIR/plugins/.libs/*.so $QTEDIR/lib/
cp -a $TSLIBINST/bin/* $QTEDIR/bin
cp -a $TSLIBINST/etc/ts.conf $QTEDIR/
cp -a $TSLIBINST/include/ts* $QTEDIR/include/
2.1 编译ARM版本QT/E库环境:
#####Build Qt/Embedded
编译之前要修改一些东西
1.在 qt-2.3.10/src/kernel/ 下,修改qwsmouse_qws.cpp程序,此文件中有3处/etc/pointercal,把这3处的etc修改成tmp
,因为开发板是在/tmp/下找到校正信息临时文件的,"pointercal"这个名子随便改,只要在接下来的环境变量设置时,写成相应的就行(看接下来的几步)
2.修改 qt-2.3.10/configs/linux-arm-g++-shared文件:
#Linking application下的SYSCONF_LIBS = -lm 修改为 SYSCONF_LIBS=-lm -lts
#Linking shared libraries 下的 SYSCONF_LINK_SHLIB=arm-linux-gcc修改为
SYSCONF_LINK_SHLIB=arm-linux-gcc -lts
修改完后,开始编译 qte-2.3.10
cd $QTEDIR
export TMAKEPATH=$TMAKEDIR/lib/qws/linux-arm-g++
export QTDIR=$QTEDIR
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QT2DIR/lib:$QTDIR/lib:$LD_LIBRARY_PATH
制作配置头文件:
mv src/tools/qconfig-large.h src/tools/qconfig-my.h
修改该配置文件,加入国际化支持:
[root@BC qt-2.3.10]# vi src/tools/qconfig-my.h
注释掉:
//#define QT_NO_TRANSFORMATIONS
//#define QT_NO_TRANSLATION等。
否则编译国际化应用程序的时候会编译不通过,出现问题,即不识别QTranslator类及函数。
配置QT/E库
./configure -xplatform linux-arm-g++ -qconfig my -no-qvfb -depths 16 -thread -tslib -I$TSLIBINST/include -L$TSLIBINST/lib
yes
显示如下信息表示配置正确:
Building on: linux-x86-g++-shared
Building for: linux-arm-g++-shared
Thread support..................... yes
Configuration...................... qconfig-my.h
Creating makefiles...
Qt is now configured for building. Just run make.
To reconfigure, run make clean and configure.
[root@BC qt-2.3.10]#
开始编译:
make sub-src
编译成功!
查看当前编译生成的库信息 为ARM版本,表示成功。
[root@BC qt-2.3.10]# file lib/*
lib/dejitter.so: ELF 32-bit LSB shared object, ARM, version 1 (ARM), not stripped
lib/fonts: directory
lib/libqte-mt.so: symbolic link to libqte-mt.so.2.3.10
lib/libqte-mt.so.2: symbolic link to libqte-mt.so.2.3.10
lib/libqte-mt.so.2.3: symbolic link to libqte-mt.so.2.3.10
lib/libqte-mt.so.2.3.10: ELF 32-bit LSB shared object, ARM, version 1 (ARM), not stripped
lib/libqte.so: symbolic link to libqte.so.2.3.10
lib/libqte.so.2: symbolic link to libqte.so.2.3.10
lib/libqte.so.2.3: symbolic link to libqte.so.2.3.10
lib/libqte.so.2.3.10: ELF 32-bit LSB shared object, ARM, version 1 (ARM), not stripped
lib/libts-0.0.so.0: symbolic link to libts-0.0.so.0.1.0
lib/libts-0.0.so.0.1.0: ELF 32-bit LSB shared object, ARM, version 1 (ARM), not stripped
lib/libts.la: broken symbolic link to ../libts.la
lib/libts.lai: ASCII English text
lib/libts.so: symbolic link to libts-0.0.so.0.1.0
lib/linear.so: ELF 32-bit LSB shared object, ARM, version 1 (ARM), not stripped
lib/variance.so: ELF 32-bit LSB shared object, ARM, version 1 (ARM), not stripped
[root@BC qt-2.3.10]#
2.2.1 编译应用程序测试该环境:
在主机上编译一个应用程序,如在qte-2.3.10/exmples/下有应用例程.
注意: 编译应用程序时,要修改arm2410QT工作目录下的tmake-1.13/lib/qws/linux-arm-g++/tmake.conf文件
将其中的: “TMAKE_LINK= arm-linux-gcc”
“TMAKE_LINK_SHLIB= arm-linux-gcc”
修改为 : “TMAKE_LINK= arm-linux-g++”
“TMAKE_LINK_SHLIB= arm-linux-g++”
俄罗斯方块游戏举例测试:在/root/arm2410QT/目录下设置编译环境变量:注意arm2410QT为自己编译好的库的环境目录
设置编译环境变量:
export TMAKEDIR=$PWD/tmake-1.13
export QT2DIR=$PWD/qt-2.3.2
export QTEDIR=$PWD/qt-2.3.10
export TMAKEPATH=$TMAKEDIR/lib/qws/linux-arm-g++
export QTDIR=$QTEDIR
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
之后在进入要编译例子目录:
[root@BC arm2410QT]# cd qt-2.3.10/examples/tetrix/
[root@BC tetrix]# /root/arm2410QT/tmake-1.13/bin/tmake -o Makefile tetrix.pro
[root@BC tetrix]# make
即可生成ARM可执行的应用程序tetrix 接下来想什么办法也可以让ARM运行它吧!方法很多 挂载 下载 这里就不罗嗦了
注释: 编写自己的Makefile时候可能要手动修改编译参数 加上 -lts
否则会提示出错:
/root/arm2410QT/qt-2.3.10/lib/libqte.so: undefined reference to `ts_close'
/root/arm2410QT/qt-2.3.10/lib/libqte.so: undefined reference to `ts_config'
/root/arm2410QT/qt-2.3.10/lib/libqte.so: undefined reference to `ts_read'
/root/arm2410QT/qt-2.3.10/lib/libqte.so: undefined reference to `ts_read_raw'
/root/arm2410QT/qt-2.3.10/lib/libqte.so: undefined reference to `ts_open'
/root/arm2410QT/qt-2.3.10/lib/libqte.so: undefined reference to `ts_fd'
collect2: ld returned 1 exit status
make: *** [tetrix] Error 1
2.2.2在ARM端运行俄罗斯方块程序:
方式:NFS 共享目录为/root/arm2410QT
这里把/root/arm2410QT设置为NFS共享目录,考虑到该目录下有我们刚刚编译好的QT/E库,省去我们再次拷贝相关库及环境目录到其他NFS共享目录的麻烦
######### ARM端运行环境变量 ##########
在ARM终端计入到arm2410QT目录
设置环境变量:
export QTDIR=$PWD/qt-2.3.10/
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_CONFFILE=$PWD/tslib-install/etc/ts.conf
export TSLIB_CONSOLEDEVICE=none
export TSLIB_CALIBFILE=$PWD/tslib-install/ts-calib.conf
export TSLIB_PLUGINDIR=$QTDIR/lib/
export QT_TSLIBDIR=$QTDIR/lib/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib
export QWS_SIZE=640x480
export QWS_MOUSE_PROTO="TPanel:/dev/input/event0 USB"
export LANG=zh_CN
insmod /mnt/yaffs/touchscreen/ts-uptech.o
校准触摸屏:
[/mnt/nfs/arm2410QT]./tslib-install/bin/ts_calibrate
xres = 640, yres = 480
执行QT/E程序:
[/mnt/nfs/arm2410QT]./tetrix -qws
./tetrix: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
[/mnt/nfs/arm2410QT]
该问题是你的QT/E运行库中缺少相关库造成的,可以在宿主机端进行拷贝操作,如:将宿主机端交叉编译器的库文件拷贝到NFS共享目录的QT的lib目录下
[root@BC tetrix]# cp /arm2410s/gui/Qt/tools/usr/local/arm/3.4.1/arm-linux/lib/libstdc++.so.6 /root/arm2410QT/qt-2.3.10/lib/
[root@BC tetrix]#
回到ARM串口终端再次执行程序:
[/mnt/nfs/arm2410QT]./tetrix -qws
Cannot create Qt/Embedded data directory: /tmp/qtembedded-0
[/mnt/nfs/arm2410QT]
该错误由于我们的ARM开发板运行QT/E程序缺少相应的目录照成,通过文件查看可以知道ARM文件中/tmp目录实际连接到/mnt/yaffs/Qtopia/tmp目录下
[/mnt/nfs/arm2410QT]ll /
drwxr-xr-x 1 502 247 872 Jan 1 1970 bin
drwxr-xr-x 1 root root 0 Jan 1 1970 dev
drwxr-xr-x 1 502 247 484 Jan 1 1970 etc
drwxr-xr-x 1 502 247 0 Jan 1 1970 host
drwxr-xr-x 1 502 247 1284 Jan 1 1970 lib
lrwxrwxrwx 1 502 247 11 Jan 1 1970 linuxrc -> bin/busybox
drwxr-xr-x 1 502 247 156 Jan 1 1970 mnt
dr-xr-xr-x 28 root root 0 Nov 11 15:08 proc
lrwxrwxrwx 1 502 247 22 Jan 1 1970 root -> /mnt/yaffs/Qtopia/root
drwxr-xr-x 1 502 247 932 Jan 1 1970 sbin
lrwxrwxrwx 1 502 247 21 Jan 1 1970 tmp -> /mnt/yaffs/Qtopia/tmp
drwxrwxrwx 1 502 247 100 Jan 1 1970 usr
drwxr-xr-x 1 root root 0 Nov 11 15:09 var
[/mnt/nfs/arm2410QT]
如果ARM系统中无该目录,那么手动创建一个tmp即可。如:
[/mnt/nfs/arm2410QT]mkdir /mnt/yaffs/Qtopia/tmp
再次运行QT/E程序:
[/mnt/nfs/arm2410QT]./tetrix -qws
Could not read calibration: /tmp/pointercal
Cannot open /dev/input/mice (No such file or directory)
上诉提示不影响系统运行,可忽略
程序正常运行!
2.3 编写HELLO程序测试QT/E环境
##### build hello for arm #######
[root@BC exp]# cd /root/arm2410QT/
设置编译环境变量:
export TMAKEDIR=$PWD/tmake-1.13
export QTEDIR=$PWD/qt-2.3.10
export TMAKEPATH=$TMAKEDIR/lib/qws/linux-arm-g++
export QTDIR=$QTEDIR
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
按上面步骤编写好hello.cpp后,通过progen/tmake等工具生成Makefile文件
[root@BC exp]# /root/arm2410QT/tmake-1.13/bin/progen -t app.t -o hello.pro
[root@BC exp]# /root/arm2410QT/tmake-1.13/bin/tmake -o Makefile hello.pro
编辑Makefile文件,在连接库的环境变量中加入触摸屏库支持:
[root@BC exp]# vi Makefile
-lts
编译程序:
[root@BC exp]# make
同样把生成的hello可执行程序放入NFS共享目录,ARM端执行即可。
三、编译本机Qtopia环境
宿主机:RH9
源码包:
工作目录:/root/x86Qtopia
############ build qtopia for x11 env #########################
mkdir x86Qtopia
cd x86Qtopia
3.1 编译qt-2.3.2包:
########### build qt-2.3.2 #########################################
设置环境变量:
export QPEDIR=$PWD/qtopia-free-2.1.1
export TMAKEDIR=$PWD/tmake-1.13
export QT2DIR=$PWD/qt-2.3.2
export QTEDIR=$PWD/qt-2.3.10
cd $QT2DIR
export TMAKEPATH=$TMAKEDIR/lib/linux-g++
export QTDIR=$QT2DIR
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
配置qt-2.3.2库
./configure -no-xft
yes
编译
make
//cp -a bin/uic $QTEDIR/bin/(该步骤可以省略)
3.2 编译qt-2.3.10包
########### build qte #########################################
设置环境变量:
cd $QTEDIR
export TMAKEPATH=$TMAKEDIR/lib/qws/linux-x86-g++
export QTDIR=$QTEDIR
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
拷贝配置文件:
cp -f $QPEDIR/src/qt/qconfig-qpe.h src/tools/
配置库环境:
./configure -system-jpeg -no-xft -qconfig qpe -qvfb -depths 4,8,16,32
yes
编译
make sub-src
3.3 编译qtopia包
################## Build Qtopia ##################################
cd $QPEDIR
设置环境变量:
export QTDIR=$QTEDIR
export PATH=$QPEDIR/bin:$PATH
配置:
./configure
编译:
make
如果以上编译出错,将qt-2.3.2/bin/uic拷贝到qt-2.3.10/bin下否则编译出错,不能使用qt-2.3.10/bin下自带的uic工具。
#######
可能出现错误:
/usr/bin/ld: cannot find -luuid
collect2: ld returned 1 exit status
make[4]: *** [../../../lib/libqpe.so.1.5.3] Error 1
###
解决办法:
#可以将e2fsprog-libs-1.37.tar.gz解压后在其目录中
./configure --enable-elf-shlibs
make clean
make
make install
进入qtopia目录重新编译:
cd qtopia-free-2.2.1/
make
编译qtopia本机环境成功!
###################################################################
追加设置qtopia本机运行环境变量:
export LD_LIBRARY_PATH=$QPEDIR/lib:$LD_LIBRARY_PATH
查看变量:
[root@BC qtopia-free-2.1.1]# echo $LD_LIBRARY_PATH
/root/Qtopia4x86/qtopia-free-2.1.1/lib:/root/Qtopia4x86/qt-2.3.10/lib:/root/Qtopia4x86/qt-2.3.2/lib:/root/Qtopia4x86/qt-2.3.10/lib:
[root@BC qtopia-free-2.1.1]# echo $PATH
/root/Qtopia4x86/qt-2.3.10/bin:/root/Qtopia4x86/qt-2.3.2/bin:/root/Qtopia4x86/qtopia-free-2.1.1/bin:/root/Qtopia4x86/qt-
2.3.10/bin:/opt/host/armv4l/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
[root@BC qtopia-free-2.1.1]#
###
执行qpe程序测试
先执行QVFB程序(/root/Qtopia4x86/qt-2.3.10/bin/目录下)
[root@BC bin]# qvfb &
[1] 11451
[root@BC bin]# Using display 0
进入qtopia目录的bin目录
[root@BC qtopia-free-2.1.1]# cd bin/
执行qpe脚本程序
[root@BC bin]# ./qpe.sh
至此,本机Qtopia环境建立成功!
备注:(默认qpe程序只是个界面,里面窗口程序并无实体,因此无法调用里面子程序,感兴趣,用户可以自己编译程序添加进来)
####################################################################
三、编译ARM端Qtopia环境
宿主机:RH9 目标机:ARM
交叉编译器:arm-linux-gcc3.4.1
编译ARM端的Qtopia,直接使用博创光盘中的gui/src目录下的脚本即可!
转贴自: