Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1721690
  • 博文数量: 199
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 6186
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-30 11:01
个人简介

Linuxer.

文章存档

2015年(4)

2014年(28)

2013年(167)

分类: LINUX

2013-06-05 09:26:31

前言:
花了3天的时间将qte的开发环境以及arm版本移植好,花费的时间多主要是一些软件的依赖关系以及环境变量的配置,还有软件本身编译的时间很长,最后终于克服重重困难,把qte移植到了开发板上。其实不难,主要是要有耐心,会分析错误及上网查资料。下面说说我的移植过程:
编译了两个版本,一个是用于PC机调试的x86版本,还有一个arm版本。开发时可以先通过x86版本以及qvfb来调试,调试通过再编译成arm版本下发到开发板上即可。

  1. 二、安装qte的pc机的x86版本
  2. 1.下载源程序
  3. ftp://ftp.qt.nokia.com/qt/source/qt-embedded-linux-opensource-src-4.5.3.tar.gz

  4. 2.解压
  5. /tmp目录下新建两个文件夹qte-x86和qte-arm,将qt-embedded-linux-opensource-src-4.5.3解压之后,把里面的文件分别全部复制到qte-x86和qte-arm中。须要说明的是:在qte-x86目录下编译x86架构的编译工具链,用于PC机上的仿真调试。在qte-arm目录下编译arm架构的编译工具链,用于交叉编译在arm开发板上运行的程序。
  6. tar -zxvf qt-embedded-linux-opensource-src-4.5.3

  7. 3.进入/tmp/qte-x86/qt-embedded-linux-opensource-src-4.5.3,运行configure生成makefile
  8. ./configure -prefix /usr/local/qte-x86 -no-qt3support -system-zlib -system-libtiff -system-libpng -qt-libmng -system-libjpeg -make libs -make examples -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-usb -qt-kbd-tty -qt-kbd-qvfb -qt-mouse-pc -no-glib -qt-mouse-qvfb

  9. 3.1 出现如下错误:
  10. The target system byte order could not be
  11. Turn on verbose messaging (-v) to see the final report.
  12. You can use the -little-endian or -big-endian switch to
  13. ./configure to continue.
  14. 解决方法:发现QMAKESPEC路径不对,设置export QMAKESPEC= /tmp/qte-x86/qt-embedded-linux-opensource-src-4.5.3/mkspecs/qws/linux-x86-g++
  15. ./configure之后就成功。

  16. 4.编译 make

  17. 4.1出现如下错误:
  18. image/qpnghandler.cpp:53:17: error: png.h:没有发现此文件
  19. 修改方法:找到该qpnghandler.cpp文件,打开后将原来的
  20. #include <png.h>
  21. #include <pngconf.h>
  22. 改为:直接到头文件目录下边,
  23. #include "/tmp/qt-embedded-linux-opensource-src-4.5.3/src/3rdparty/libpng/png.h"
  24. #include "/tmp/qt-embedded-linux-opensource-src-4.5.3/src/3rdparty/libpng/pngconf.h"
  25. 再make编译就能通过。

  26. 4.2出现如下错误:
  27. /usr/bin/ld: cannot find –lpng
  28. 解决方法:sudo apt-get install libpng12-0 libpng12-dev
  29. /usr/bin/ld:cannot find -lxxx
  30. 意思是编译过程找不到对应库文件。其中-lxxx表示链接库文件libxxx.so。

  31. 一般出现这种错误有以下几种原因:
  32. 1.系统缺乏对应的库文件
  33. 2.库文件版本不对应
  34. 3.库文件链接错误
  35. 4.库文件路径设置不正确

  36. 对于前2种情况,可以通过下载安装lib来解决:
  37. sudo apt-get install libxxx-dev(上面编译Qt的情况大多是这样)

  38. 而对于第3种情况,通过find或者locate命令定位到链接文件,查看链接文件是否正确的指向了lib文件。如果不是,用 ln -sf */libxxx.so.x */libxxx.so 命令修改。

  39. 对于最后一种情况,可以到/etc/ld.so.conf.d目录下,修改其中任意一份conf文件(也可自建conf),将lib所在的目录写进去,然后在终端输入ldconfig更新缓存。

  40. 4.3又出现找不到头文件错误
  41. #include <jpeglib.h>
  42. 改为:
  43. #include "/tmp/qt-embedded-linux-opensource-src-4.5.3/src/3rdparty/libjpeg/jpeglib.h"

  44. 4.4之后又出现错误:
  45. /usr/bin/ld: cannot find –ljpeg
  46. 解决方法:sudo apt-get install libjpeg62-dev

  47. 4.5又出现找不到头文件错误
  48. #include "tiffio.h"改为
  49. #include "/tmp/qt-embedded-linux-opensource-src-4.5.3/src/3rdparty//libtiff/libtiff/tiffio.h"

  50. 4.6然后出现错误
  51. /usr/bin/ld: cannot find -ltiff
  52. sudo apt-get install libtiff4 libtiff4-dev libtiffxx0c2

  53. 编译通过

  54. 5.make install (安装到了/usr/local/qte-x86,最好事先建立该该文件夹)


  55. 三、安装qte的arm版本
  56. 1.下载源程序及解压,同上步骤
  57. 2.确认tslib已经安装好(参见tslib的安装)
  58. 3.修改交叉环境变量
  59. /usr/local/qt-4.7.3-linux-arm/mkspecs/qws/linux-arm-g++/qmake.conf文件中修改如下:

  60. QMAKE_CC = /root/tools/arm-2009q1/bin/arm-none-linux-gnueabi-gcc
  61. QMAKE_CXX = /root/tools/arm-2009q1/bin/arm-none-linux-gnueabi-g++
  62. QMAKE_LINK = /root/tools/arm-2009q1/bin/arm-none-linux-gnueabi-g++
  63. QMAKE_LINK_SHLIB = /root/tools/arm-2009q1/bin/arm-none-linux-gnueabi-g++
  64. QMAKE_AR = /root/tools/arm-2009q1/bin/arm-none-linux-gnueabi-ar cqs
  65. QMAKE_OBJCOPY = /root/tools/arm-2009q1/bin/arm-none-linux-gnueabi-objcopy
  66. QMAKE_STRIP = /root/tools/arm-2009q1/bin/arm-none-linux-gnueabi-strip
  67. QMAKE_INCDIR     = /usr/local/tslib/include/
  68. QMAKE_LIBDIR = /usr/local/tslib/lib/

  69. 4.修改系统环境变量
  70. export QMAKESPEC=/tmp/qt-embedded-linux-opensource-src-4.5.3/mkspecs/qws/linux-arm-g++
  71. 这里还要注意PATH环境变量:(PATH环境变量错误也会导致下边configure时发生众多错误,很难改,我是重启了系统之后重新设置,之后才弄好)
  72. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/qt/bin:/root/tools/arm-2009q1/bin:/root/tools

  73. 5.configure
  74. ./configure -prefix /usr/local/qte-arm -no-qt3support -qt-zlib -qt-libtiff -qt-libpng -qt-libmng -qt-libjpeg -make libs -nomake 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 -verbose -I/usr/local/tslib/include -L/usr/local/tslib/lib

  75. 6. make

  76. 7.make install

  77. 8.为了方便使用qte-x86和qte-arm工具链来编译程序,必要的环境变量还是得设置一下的。其实,在编译Qt程序时,我们一般只是使用到了qmake工具,所以只要在~/.bashrc中添加几个alias就可以了。
  78. gedit ~/.bashrc
  79. 在该文件最后加上:
  80. alias qte-x86-make='/usr/local/qte-x86/bin/qmake'
  81. alias qte-arm-make='/usr/local/qte-arm/bin/qmake'
  82. 到这里,交叉编译环境以及要移植的环境都搭建好了。

  83. 四,制作配置文件系统

  84. 1.在根文件系统的根目录下创建qte-arm,tslib目录。即/qte-arm和/tslib.我们把/usr/local/qte-arm目录下的lib目录和include目录复制到开发板文件系统的qte-arm文件夹。然后将/usr/local/tslib/下面的所有文件都复制到开发板文件系统的tslib目录包括lib,bin等。

  85. 2.进入开发板的/tslib/etc文件夹,修改触屏配置
  86. gedit /tslib/etc/ts.conf
  87. 修改如下:
  88. module_raw input #就是在把这个之前的#号去掉,其他不变
  89. module pthres pmin=1
  90. module variance delta=30
  91. module dejitter delta=100
  92. module linear

  93. 3.最后,就是设置开发板的环境变量了,在你制作的文件系统中,进入/etc修改profile文本添加以下信息
  94. export QTDIR=/qte-arm
  95. //添加路径
  96. export PATH=$QTDIR/bin:$PATH
  97. //指定tslib主目录位置
  98. export TSLIB_ROOT=/tslib
  99. //指定触摸屏设备
  100. export TSLIB_TSDEVICE=/dev/input/touchscreen0
  101. //指定触摸屏校准文件pointercal存放位置
  102. export TSLIB_CALIBFILE=/etc/pointercal
  103. //指定TSLIB配置文件的位置
  104. export TSLIB_CONFFILE=$TSLIB_ROOT/etc/ts.conf
  105. //指定触摸屏插件所在路径
  106. export TSLIB_PLUGINDIR=$TSLIB_ROOT/lib/ts
  107. //指定帧缓冲设备
  108. export TSLIB_FBDEVICE=/dev/fb0
  109. //设定控制台设备为none否则默认为/dev/tty,这样会出现”open consol device:No such file or directory KD…..”的错误
  110. export TSLIB_CONSOLEDEVICE=none
  111. //指定TSLIB的库文件路径
  112. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:TSLIB_ROOT/lib
  113. //指定触摸屏设备
  114. export QWS_MOUSE_PROTO=tslib:/dev/input/touchscreen0

  115. 五,测试
  116. /opt/code编写三个文件如下:这些代码是在网上摘录的
  117. //finddialog.cpp
  118. #include <QtGui>
  119. #include "finddialog.h"
  120. FindDialog::FindDialog(QWidget *parent)
  121.     :QDialog(parent)
  122. {
  123.   label=new QLabel(tr("Find &what:"));
  124.   lineEdit=new QLineEdit;
  125.   label->setBuddy(lineEdit);
  126.      caseCheckBox=new QCheckBox(tr("Match &case"));
  127.   backwardCheckBox=new QCheckBox(tr("Search &backward"));
  128.   findButton=new QPushButton(tr("&Find"));
  129.   findButton->setDefault(true);
  130.   findButton->setEnabled(false);
  131.      closeButton=new QPushButton(tr("Close"));
  132.     connect(lineEdit,SIGNAL(textChanged(const QString &)),this,SLOT(enableFindButton(const QString &)));
  133.   connect(findButton,SIGNAL(clicked()),this,SLOT(findClicked()));
  134.   connect(closeButton,SIGNAL(clicked()),this,SLOT(close()));
  135.     QHBoxLayout *topLeftLayout =new QHBoxLayout;
  136.   topLeftLayout->addWidget(label);
  137.   topLeftLayout->addWidget(lineEdit);
  138.     QVBoxLayout *leftLayout=new QVBoxLayout;
  139.   leftLayout->addLayout(topLeftLayout);
  140.   leftLayout->addWidget(caseCheckBox);
  141.   leftLayout->addWidget(backwardCheckBox);
  142.   QVBoxLayout *rightLayout=new QVBoxLayout;
  143.   rightLayout->addWidget(findButton);
  144.   rightLayout->addWidget(closeButton);
  145.   rightLayout->addStretch();
  146.      QVBoxLayout *mainLayout=new QVBoxLayout;
  147.   mainLayout->addLayout(leftLayout);
  148.   mainLayout->addLayout(rightLayout);
  149.   setLayout(mainLayout);
  150.      setWindowTitle(tr("Find"));
  151.   setFixedHeight(sizeHint().height());

  152. }
  153. void FindDialog::findClicked()
  154. {
  155.  QString text =lineEdit->text();
  156.  Qt::CaseSensitivity cs=caseCheckBox->isChecked() ? Qt::CaseSensitive :Qt::CaseInsensitive;
  157.  if(backwardCheckBox->isChecked())
  158.  {
  159.   emit findPrevious(text,cs);
  160.  }
  161.  else
  162.  {
  163.   emit findNext(text,cs);
  164.  }
  165. }

  166. void FindDialog::enableFindButton(const QString &text)
  167. {
  168.  findButton->setEnabled(!text.isEmpty());
  169. }

  170. //finddialog.h
  171. #ifndef FINDDIALOG_H
  172. #define FINDDIALOG_H

  173. #include <QDialog>

  174. class QCheckBox;
  175. class QLabel;
  176. class QLineEdit;
  177. class QPushButton;

  178. class FindDialog : public QDialog
  179. {
  180.  Q_OBJECT
  181. public:
  182.     FindDialog(QWidget *parent=0);
  183. signals:
  184.     void findNext(const QString &str,Qt::CaseSensitivity cs);
  185.     void findPrevious(const QString &str,Qt::CaseSensitivity cs);
  186. private slots:
  187.     void findClicked();
  188.     void enableFindButton(const QString &text);
  189. private:
  190.     QLabel *label;
  191.     QLineEdit *lineEdit;
  192.     QCheckBox *caseCheckBox;
  193.     QCheckBox *backwardCheckBox;
  194.     QPushButton *findButton;
  195.     QPushButton *closeButton;

  196. };
  197. #endif

  198. //main.cpp
  199. #include <QtGui/QApplication>
  200. #include "finddialog.h"

  201. int main(int argc, char *argv[])
  202. {
  203.     QApplication a(argc, argv);
  204.     FindDialog *dialog=new FindDialog;
  205.     dialog->show();
  206.     return a.exec();
  207. }

  208. 在编写一个hello.pro文件,代码如下:
  209. HEADERS = finddialog.h
  210. SOURCES = finddialog.cpp main.cpp
  211. CONFIG+=qt warn_off release
  212. 在当前目录执行:

  213. 1.qte-x86-make hello.pro

  214. 用qte-x86-make hello.pro编译时
  215. qmake后出现错误 qt_config.prf:10: include(file) requires one argument.
  216. 解决方法:
  217. 环境变量设置的问题,将环境变量QMAKESPEC修改指向当前编译平台的路径:
  218. export QMAKESPEC=/usr/local/qt/mkspecs/linux-g++
  219. 编译通过

  220. 2.make
  221. 会生成一个可执行的hello。我们继续执行qvfb &,打开qvfb。然后执行./hello -qws,会出现如下图面。本机交叉编译测试成功。

  222. 3.接着我们执行make clean。主要是消除上面qte-x86-make产生的文件,不然我们在下面使用qte-arm-make的时候会报错。继续执行:
  223. qte-arm-make hello.pro

  224. 当用交叉编译工具时,环境变量QMAKESPEC修改指向当前编译平台的路径
  225. export QMAKESPEC=/usr/local/qte-arm/mkspecs/qws/linux-arm-g++

  226. 4.make
  227. 将生成的hello可执行文件放到开发板文件系统的根目录,执行./hello -qws,就可出现画面。

阅读(6841) | 评论(0) | 转发(5) |
给主人留下些什么吧!~~