Qt-5.3.2 在友善Smart210开发板的移植记录

本文详细介绍了如何在基于Ubuntu14.04的ARM-Linux平台(如FrendlyARM的Smart210开发板)上成功移植Qt5.3.2,并配置了必要的环境变量以支持Qt程序在嵌入式Linux平台上的运行。重点包括交叉编译Qt源码、移植tslib以支持触摸屏、以及如何在ARM平台上设置Qt的QPA插件来启动Qt窗口系统服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  平台说明

主机平台: Ubuntu 14.04

交叉工具链: FrendlyARM的 arm-linux-gcc-4.5.1-v6-vfp-20120301.tgz

目标平台:FrendlyARM的Smart210开发板。(Soc是三星的S5PV210,内核是cortex-a8,下面的移植方法是普适的,不是此平台的也可参考下面的移植步骤)

Qt版本: Qt-5.3.2


  Qt5.3.2在ARM-Linux平台(Mini210开发板)的移植

进入Qt5.3.2的源码顶级目录,按照Linux系统中自编译软件通用的三个步骤依次执行 ./configure 、make 、make install 即可完成Qt5的编译安装。在执行之前,首先看一下configure的帮助,了解一下各个配置项的作用。

$ ./configure --help >help.txt ; vi help.txt


配置时需要注意的几点是:

如果是交叉编译,需要配置 xplatform选项,比如要在arm-linux平台上移植Qt的话,就在配置项中加上 -xplatform linux-arm-gnueabi-g++ ,Qt5支持的交叉平台都可在源码顶层目录中的 /qtbase/mkspecs/ 下找到,每个子目录名代表一个交叉平台的名字,移植Qt时应根据自己的实际情况修改平台对应的子目录下的qmake.conf文件,它定义了一些与平台相关的环境变量,如交叉编译器等;

最好不要在编译Qt时使能 c++11,一方面你的编译器可能不支持,另一方面使能这一项后可能出现一部分编译错误;

如果需要openGL,就需要用 -opengl选项指定opengl的api,对于嵌入式平台,一般使用 opengl ES2,配置选项中加入" -opengl es2 " 。不过想使用openGL可能会比较麻烦,因为openGL一般在有硬件图形加速的条件下才能高效运行,而这需要显卡或Soc厂家提供openGL的支持库,但并不是所有Soc都能找到对应的支持库,比如三星就没有提供S5PV210的openGL库,所以我这里编译的Qt也是没有opengl的。(openGL的替代方案:如果没有厂家提供的硬件图形库,可以考虑使用纯软件实现的opengl,这样的软件库有很多是开源的,如mesa3D库等,不过纯软件实现的opengl在效率方面肯定要比带硬件加速的低很多,而且要想在嵌入式平台上使用,必须将opengl的软件库也交叉编译出来,我在交叉编译mesa3D时遇到了些问题,所以目前还没能在开发板上用上openGL);

如果想让Qt程序支持多点触摸,在配置时可能需要加上 -mtdev 和 -xinput2 选项,在help中可以找到这两个选项。mtdev包含了应用程序对多点触摸协议的支持,xinput2实现了Linux的输入子系统对多点触摸的支持。在我这里加上这两个选项的话配置会出错,可能还缺乏一些库,所以最后我没有使用这两个选项;

另外,Qt5默认的qreal类型是64bit的double,如果希望用float类型定义qreal,则在配置选项中加入"-qreal float"。


我的编译过程如下:

首先修改 qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf,内容如下:

 

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1.  
  2. qmake configuration for building with arm-linux-gnueabi-g++  
  3.  
  4.   
  5. MAKEFILE_GENERATOR      UNIX  
  6. CONFIG                 += incrementar gdb_dwarf_index  
  7. QMAKE_INCREMENTAL_STYLE sublib  
  8. QT_QPA_DEFAULT_PLATFORM linux #eglfs  
  9. QMAKE_CFLAGS_RELEASE   += -O2 -march=armv7-a    
  10. QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv7-a    
  11.   
  12. include(../common/linux.conf)  
  13. include(../common/gcc-base-unix.conf)  
  14. include(../common/g++-unix.conf)  
  15.   
  16. modifications to g++.conf  
  17. QMAKE_CC                arm-none-linux-gnueabi-gcc  
  18. QMAKE_CXX               arm-none-linux-gnueabi-g++  
  19. QMAKE_LINK              arm-none-linux-gnueabi-g++  
  20. QMAKE_LINK_SHLIB        arm-none-linux-gnueabi-g++  
  21.   
  22. modifications to linux.conf  
  23. QMAKE_AR                arm-none-linux-gnueabi-ar cqs  
  24. QMAKE_OBJCOPY           arm-none-linux-gnueabi-objcopy  
  25. QMAKE_NM                arm-none-linux-gnueabi-nm -P  
  26. QMAKE_STRIP             arm-none-linux-gnueabi-strip  
  27. load(qt_config)  


然后执行:

 

 

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. ./configure -release -opensource -xplatform linux-arm-gnueabi-g++ -prefix /opt/Qt-5.3.2/armv7-a -no-c++11 -qreal float  

 

配置结果为:

 

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1.    Configure summary  
  2.   
  3. Building on:   linux-g++ (i386, CPU features:)  
  4. Building for:  linux-arm-gnueabi-g++ (arm, CPU features:)  
  5. Platform notes:  
  6.   
  7.             Also available for Linux: linux-kcc linux-icc linux-cxx  
  8.           
  9. Build options:  
  10.   Configuration .......... accessibility alsa audio-backend clock-gettime clock-monotonic compile_examples concurrent cross_compile evdev eventfd freetype full-config getaddrinfo getifaddrs iconv inotify ipv6ifname large-config largefile linuxfb medium-config minimal-config mremap nis no-harfbuzz no-pkg-config openssl pcre png posix_fallocate precompile_header qpa qpa reduce_exports release rpath shared small-config system-jpeg system-png system-zlib   
  11.   Build parts ............ libs examples  
  12.   Mode ................... release  
  13.   Using C++11 ............ no  
  14.   Using PCH .............. yes  
  15.   Target compiler supports:  
  16.     iWMMXt/Neon .......... no/auto  
  17.   
  18. Qt modules and options:  
  19.   Qt D-Bus ............... no  
  20.   Qt Concurrent .......... yes  
  21.   Qt GUI ................. yes  
  22.   Qt Widgets ............. yes  
  23.   Large File ............. yes  
  24.   QML debugging .......... yes  
  25.   Use system proxies ..... no  
  26.   
  27. Support enabled for:  
  28.   Accessibility .......... yes  
  29.   ALSA ................... yes  
  30.   CUPS ................... no  
  31.   Evdev .................. yes  
  32.   FontConfig ............. no  
  33.   FreeType ............... yes (bundled copy)  
  34.   Glib ................... no  
  35.   GTK theme .............. no  
  36.   HarfBuzz ............... no  
  37.   Iconv .................. yes  
  38.   ICU .................... no  
  39.   Image formats:   
  40.     GIF .................. yes (plugin, using bundled copy)  
  41.     JPEG ................. yes (plugin, using system library)  
  42.     PNG .................. yes (in QtGui, using system library)  
  43.   journald ............... no  
  44.   mtdev .................. no  
  45.   Networking:   
  46.     getaddrinfo .......... yes  
  47.     getifaddrs ........... yes  
  48.     IPv6 ifname .......... yes  
  49.     OpenSSL .............. yes (loading libraries at run-time)  
  50.   NIS .................... yes  
  51.   OpenGL OpenVG:   
  52.     EGL .................. no  
  53.     OpenGL ............... no  
  54.     OpenVG ............... no  
  55.   PCRE ................... yes (bundled copy)  
  56.   pkg-config ............. no   
  57.   PulseAudio ............. no  
  58.   QPA backends:   
  59.     DirectFB ............. no  
  60.     EGLFS ................ no  
  61.     KMS .................. no  
  62.     LinuxFB .............. yes  
  63.     XCB .................. no  
  64.   Session management ..... yes  
  65.   SQL drivers:   
  66.     DB2 .................. no  
  67.     InterBase ............ no  
  68.     MySQL ................ no  
  69.     OCI .................. no  
  70.     ODBC ................. no  
  71.     PostgreSQL ........... no  
  72.     SQLite ............. no  
  73.     SQLite ............... yes (plugin, using bundled copy)  
  74.     TDS .................. no  
  75.   udev ................... no  
  76.   xkbcommon .............. no  
  77.   zlib ................... yes (system library)  


 

配置完成后执行:

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. make -j4  
  2. sudo make install -j4  

  添加 tslib 支持

为了使单点触摸屏可用,还需要编译Qt的tslib插件,这需要首先交叉编译好tslib,tslib的编译过程参见:

http://blog.youkuaiyun.com/newthinker_wei/article/details/8639276

友善之臂的板子使用了 touchscreen-1wire,这需要按照上文中的步骤对tslib的源码打上补丁(在tslib的源码中添加了一个一线触摸屏的插件)。非友善之臂的板子一般不用打补丁。

另一个有用的链接在这儿,这是友善专门为tslib做的一线触摸屏的插件,有源码,上面那篇文章应该也是参考这个源码的:

 

http://www.arm9home.net/read.php?tid-16105.html


注意,对于友善之臂的开发板,如果使用的是单点电阻触摸屏,使用上面的方式移植tslib就可以了。但是对于多点的电容触摸屏,上面的两个网址给出的源码都不适用了,友善的多点触摸屏使用的是goodix公司出的触摸屏,goodix驱动的接口跟友善之前用的触摸屏不一样。因此如果想使用tslib,需要再单独为goodix写个TSLIB插件。tslib源码的plugins目录中就是各个插件的代码,可以参考一下他们,都很简单(主要是实现一个read函数)。但要自己写电容屏的插件貌似比较困难,因为要对驱动程序中多点触摸的数据协议有所了解,这样才能从电容屏的数据中提取出单点数据。友善提供了friendlyarm-ts-mtinput.so 文件(但并没有源码),该文件就在友善自带的tslib中,默认目录为/usr/lib/ts/friendlyarm-ts-mtinput.so。把这个库拷贝到自己编译的tslib插件目录中,再修改配置文件ts.conf,即可使tslib工作。

将编译出来的tslib拷贝到库开发板后,还需要在板子上设置TSLIB的环境变量,主要的几个变量如下:

 

[html]  view plain copy
  1. #! /bin/sh  
  2. "source" this file when wanna run Qt application on the ARM Board.  
  3.   
  4. ###############  the below lines are for stardard TSLIB ##################  
  5. export TSLIB_ROOT=/opt/tslib  
  6. export TSLIB_CALIBFILE=$TSLIB_ROOT/etc/pointercal  
  7. export TSLIB_CONFFILE=$TSLIB_ROOT/etc/ts.conf  
  8. export TSLIB_PLUGINDIR=$TSLIB_ROOT/lib/ts  
  9. export TSLIB_TSDEVICE=/dev/touchscreen-1wire  
  10. #export TSLIB_TSDEVICE=/dev/input/event2  
  11.   
  12. ################  the below lines are optional ##############  
  13. #export TSLIB_FBDEVICE=/dev/fb0  
  14. #export TSLIB_CONSOLEDEVICE=none  

此外还要修改 ts.conf文件:

 

 

[html]  view plain copy
  1. #module_raw one_wire_ts_input  
  2. module_raw friendlyarm-ts-mtinput #使用友善提供的电容屏TSLIB插件。需要先将friendlyarm-ts-mtinput.so拷贝到TSLIB_PLUGINDIR目录中  
  3.   
  4. module pthres pmin=1  
  5. module variance delta=30  
  6. module dejitter delta=100  
  7. module linear  

 

到此为止 tslib 就基本能用了,首次使用时应先运行 ts_calibrate 进行触摸屏校准。我用的这个版本的tslib自带的ts_calibrate程序不太好用,所以我依然使用友善提供的ts_calibrate进行校准。

有了tslib后,进入Qt源码目录中的 "qtbase/src/plugins/generic/tslib/",运行 qmake 生成 Makefile,并在Makefile中将tslib的头文件和库文件路径添加到编译链接选项中(-I /...tslib/include  -L/.../tslib/lib);然后运行 make 和 make install即可。这时,Qt5安装目录的 "plugins/generic/"目录下就出现"libqtslibplugin.so"这个库文件了。

  运行Qt程序

需要说明的是,Qt5.0开始,Qt自身不再单独实现窗口系统,QWS不复存在,取而代之的新机制是QPA(Qt平台抽象),QPA使得Qt对不同平台的支持变得更加灵活,当需要支持一个新平台时,只需为该平台编写一个QPA插件。

With the release of Qt 5.0, Qt no longer contains its own window system implementation: QWS is no longer a supported platform. For single-process use cases, theQt Platform Abstraction is a superior solution......参考 http://qt-project.org/doc/qt-5/embedded-linux.html

编译完Qt后,只需将生成的lib和plugins文件夹拷贝到开发板,另外,当在嵌入式Linux平台上运行应用程序前,应根据自己平台的实际情况提前设置好下面几个环境变量:

[html]  view plain copy
  1. export QT_QPA_PLATFORM_PLUGIN_PATH=/opt/Qt-5.3.2/armv7-a/plugins/platforms  
  2. export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0  
  3. export QT_QPA_FONTDIR=/opt/Qt-5.3.2/armv7-a/lib/fonts  
  4. export QT_QPA_GENERIC_PLUGINS=tslib:/dev/touchscreen-1wire  #使用tslib插件  

然后就可以运行Qt程序了

以前Qt4的程序在嵌入式Linux平台运行时,需要在命令行输入-qws选项以启动Qt窗口系统服务,如" ./HelloWorld -qws";而使用Qt5后,不再需要-qws,而需要通过-platform来指定要使用的QPA插件,如" ./HelloWorld -platform linuxfb",如果不指定,则用默认的QPA插件,默认的QPA插件通过上面的QT_QPA_PLATFORM变量指定。

附: 在Ubuntu 14.04上编译Qt ---(请注意,本小节编译的是PC版Qt,不是ARM版,ARM版Qt的编译过程请参考本文第2节)

在Ubuntu 14.04上编译Qt就简单多了,缺少的组件可以很容易下载到。

首先安装opengl支持(mesa3d),

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. sudo apt-get install mesa-common-dev  libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev  

如果需要,再安装Qt D-Bus的支持。

然后configure,configure过程中可能出现一些错误,基本都是缺少某个库引起的,配置过程中根据错误提示,用apt-get install或Ubuntu Software Center搜索安装缺少的组件。

 

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. ./configure -release -opensource -prefix /opt/Qt-5.3.2/x86 -no-c++11 -qreal float -opengl  

配置结果为:

 

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1.    Configure summary  
  2.   
  3. Build type:    linux-g++ (i386, CPU features:)  
  4. Platform notes:  
  5.   
  6.             Also available for Linux: linux-kcc linux-icc linux-cxx  
  7.           
  8. Build options:  
  9.   Configuration .......... accessibility accessibility-atspi-bridge audio-backend avx avx2 clock-gettime clock-monotonic compile_examples concurrent dbus evdev eventfd fontconfig full-config getaddrinfo getifaddrs glib iconv inotify ipv6ifname large-config largefile libudev linuxfb medium-config minimal-config mremap nis no-harfbuzz opengl pcre png posix_fallocate precompile_header qpa qpa reduce_exports reduce_relocations release rpath shared small-config sse2 sse3 sse4_1 sse4_2 ssse3 system-freetype system-jpeg system-png system-zlib xcb xcb-glx xcb-plugin xcb-render xcb-sm xcb-xlib xinput2 xkbcommon-qt xlib xrender   
  10.   Build parts ............ libs tools examples  
  11.   Mode ................... release  
  12.   Using C++11 ............ no  
  13.   Using PCH .............. yes  
  14.   Target compiler supports:  
  15.     SSE2/SSE3/SSSE3 ...... yes/yes/yes  
  16.     SSE4.1/SSE4.2 ........ yes/yes  
  17.     AVX/AVX2 ............. yes/yes  
  18.   
  19. Qt modules and options:  
  20.   Qt D-Bus ............... yes (loading dbus-1 at runtime)  
  21.   Qt Concurrent .......... yes  
  22.   Qt GUI ................. yes  
  23.   Qt Widgets ............. yes  
  24.   Large File ............. yes  
  25.   QML debugging .......... yes  
  26.   Use system proxies ..... no  
  27.   
  28. Support enabled for:  
  29.   Accessibility .......... yes  
  30.   ALSA ................... no  
  31.   CUPS ................... no  
  32.   Evdev .................. yes  
  33.   FontConfig ............. yes  
  34.   FreeType ............... yes (system library)  
  35.   Glib ................... yes  
  36.   GTK theme .............. no  
  37.   HarfBuzz ............... no  
  38.   Iconv .................. yes  
  39.   ICU .................... no  
  40.   Image formats:   
  41.     GIF .................. yes (plugin, using bundled copy)  
  42.     JPEG ................. yes (plugin, using system library)  
  43.     PNG .................. yes (in QtGui, using system library)  
  44.   journald ............... no  
  45.   mtdev .................. no  
  46.   Networking:   
  47.     getaddrinfo .......... yes  
  48.     getifaddrs ........... yes  
  49.     IPv6 ifname .......... yes  
  50.     OpenSSL .............. no  
  51.   NIS .................... yes  
  52.   OpenGL OpenVG:   
  53.     EGL .................. no  
  54.     OpenGL ............... desktop  
  55.     OpenVG ............... no  
  56.   PCRE ................... yes (bundled copy)  
  57.   pkg-config ............. yes   
  58.   PulseAudio ............. no  
  59.   QPA backends:   
  60.     DirectFB ............. no  
  61.     EGLFS ................ no  
  62.     KMS .................. no  
  63.     LinuxFB .............. yes  
  64.     XCB .................. yes (system library)  
  65.       EGL on ........... no  
  66.       GLX ................ yes  
  67.       MIT-SHM ............ yes  
  68.       Xcb-Xlib ........... yes  
  69.       Xcursor ............ yes (loaded at runtime)  
  70.       Xfixes ............. yes (loaded at runtime)  
  71.       Xi ................. no  
  72.       Xi2 ................ yes  
  73.       Xinerama ........... yes (loaded at runtime)  
  74.       Xrandr ............. yes (loaded at runtime)  
  75.       Xrender ............ yes  
  76.       XKB ................ no  
  77.       XShape ............. yes  
  78.       XSync .............. yes  
  79.       XVideo ............. yes  
  80.   Session management ..... yes  
  81.   SQL drivers:   
  82.     DB2 .................. no  
  83.     InterBase ............ no  
  84.     MySQL ................ no  
  85.     OCI .................. no  
  86.     ODBC ................. no  
  87.     PostgreSQL ........... no  
  88.     SQLite ............. no  
  89.     SQLite ............... yes (plugin, using bundled copy)  
  90.     TDS .................. no  
  91.   udev ................... yes  
  92.   xkbcommon .............. yes (bundled copy, XKB config root: /usr/share/X11/xkb)  
  93.   zlib ................... yes (system library)  
  94.   
  95. NOTE: libxkbcommon and libxkbcommon-x11 0.4.1 or higher not found on the system, will use   
  96. the bundled version from 3rd party directory.  

 


最后make和make install即可。


 

另外,编译完Qt5.3.2后,发现Qt assistant打开之后内容是空的,查询不到任何东西。需要打开assistant,点击Edit->preference菜单,选择Documents选项卡,点击add向assistant添加文档,文档类型为 *.qch 。但Qt5中似乎文档并不是现成的,需要在编译完Qt后再去编译他的文档。步骤为:

进入已经编译过的Qt源码顶层目录,输入

 

[html]  view plain copy
  1. make docs  
这条指令会生成Qt各个模块的文档,但这些文档分散于不同的子源码目录中,最好将他们集中拷贝出来放到Qt的安装目录中,我的做法如下,当执行完make docs后,在源码顶层目录输入:(/opt/Qt-5.3.2是我的安装目录)

 

 

[html]  view plain copy
  1. sudo mkdir /opt/Qt-5.3.2/docs_for_assistant  
  2. sudo cp `find ./ -name *.qch` /opt/Qt-5.3.2/docs_for_assistant  
然后打开assistant,将 /opt/Qt-5.3.2/docs_for_assistant 目录中的*.qch文件全部add进去。

转自:
http://blog.youkuaiyun.com/newthinker_wei/article/details/39560109
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值