分享

Qt移植:Ubuntu16.04 交叉编译qt5.9.6详细教程

 XeonGate 2019-05-30

https://blog.csdn.net/christine14122/article/details/83621585

          博主是嵌入式小萌新,项目需要移植qt到arm开发板上,历经千辛万苦解决了各种问题,最后终于成功了,所以整理了开发笔记给更多的小伙伴参考。

1.准备阶段

①下载交叉编译器aarch65-linux-gnu,下载地址为:https://releases./components/toolchain/binaries/6.2-2016.11/aarch64-linux-gnu/

②下载Qt5.9.6源码,下载地址为:http://download./archive/qt/5.9/5.9.6/single/

③下载Qtcreator安装包,下载地址为:http://download./archive/qt/5.9/5.9.6/

④安装虚拟机VMware® Workstation 14 Pro和Ubuntu16.04.5 LTS,博主的虚拟机版本如下图:

⑤将文件分别存放在相应文件夹下并解压:

****.tar.gz 文件的解压命令是 :tar -zxvf ****.tar.gz

****.tar.xz 文件的解压命令是 :tar xvJf ****.tar.xz

第一步的准备工作已完成。


2. 安装交叉编译器:

交叉编译器解压之后的路径为:/home/admin/Qt_Env/Cross-compiler/

①查看当前环境变量命令:echo $PATH

②在/etc/profile中添加新的环境变量:

  • 执行命令:gedit /etc/profile

  • 在文件末尾添加:export PATH=$PATH:/home/admin/Qt_Env/Cross-compiler/aarch64-linux-gnu/bin

  • 执行命令:source /etc/profile

③再次执行echo $PATH

 

可以看到环境变量已经添加上了。

④验证编译器是否安装成功

  • 执行命令:aarch64-linux-gnu-g++ -v

终端显示编译器信息如下:

编译器安装成功。

注意:在/etc/profile中改变的环境变量是临时的,重启虚拟机或重启终端会导致环境变量修改不生效,所以在编译qt之前一定要确定交叉编译器安装成功,如果执行④打印的是gcc的版本信息,那么可能是编译器路径不对,或者多执行几次source /etc/profile即可。


3.交叉编译qt5.9.6

①配置qt的configure

在目录/home/Qt_Env/Qt_opensource下创建 qt_compiler_conf.sh文件,文件是configure的配置项,关于配置项的说明资料很多,在此不在赘述。

  1. #!/bin/sh
  2. ./configure -prefix /opt/aarch64/qt596_64/qt_sdk \
  3. -opensource \
  4. -debug \
  5. -confirm-license \
  6. -xplatform linux-arm-gnueabi-g++ \
  7. -no-opengl \
  8. -no-pch \
  9. -shared \
  10. -no-iconv \
  11. -no-xcb \

②修改qmake文件

安装目录打开:/home/hytera/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtbase/mkspecs/linux-arm-gnueabi-g++,打开qmake.conf文件,修改编译器:

  1. #
  2. # qmake configuration for building with arm-linux-gnueabi-g++
  3. #
  4. MAKEFILE_GENERATOR = UNIX
  5. CONFIG += incremental
  6. QMAKE_INCREMENTAL_STYLE = sublib
  7. include(../common/linux.conf)
  8. include(../common/gcc-base-unix.conf)
  9. include(../common/g++-unix.conf)
  10. QT_QPA_DEFAULT_PLATFORM=linuxfb
  11. # modifications to g++.conf
  12. QMAKE_CC = aarch64-linux-gnu-gcc
  13. QMAKE_CXX = aarch64-linux-gnu-g++
  14. QMAKE_LINK = aarch64-linux-gnu-g++
  15. QMAKE_LINK_SHLIB = aarch64-linux-gnu-g++
  16. # modifications to linux.conf
  17. QMAKE_AR = aarch64-linux-gnu-ar cqs
  18. QMAKE_OBJCOPY = aarch64-linux-gnu-objcopy
  19. QMAKE_NM = aarch64-linux-gnu-nm -P
  20. QMAKE_STRIP = aarch64-linux-gnu-strip
  21. load(qt_config)

注意:arm开发板上显示屏的驱动是基于fb的话,记得在文件中添加QT_QPA_DEFAULT_PLATFORM=linuxfb。

③执行qt_compiler_conf.sh配置文件

※ 在终端执行命令:./qt_compiler_conf.sh 

※ 或者,博主将终端打印的日志重定向到了confLog.txt文件中,方便查看,故执行的命令是:./qt_compiler_conf.sh  2>&1 | tee confLog.txt

※ 执行结果为:

  1. + cd qtbase
  2. + /home/hytera/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtbase/configure -top-level -prefix /opt/aarch64/qt596_64/qt_sdk -opensource -debug -confirm-license -xplatform linux-arm-gnueabi-g++ -no-opengl -no-pch -shared -no-iconv -xcb
  3. Creating qmake...
  4. Done.
  5. This is the Qt Open Source Edition.
  6. You have already accepted the terms of the Open Source license.
  7. Running configuration tests...
  8. Done running configuration tests.
  9. Configure summary:
  10. Building on: linux-g++ (x86_64, CPU features: mmx sse sse2)
  11. Building for: linux-arm-gnueabi-g++ (arm64, CPU features: neon)
  12. Configuration: cross_compile compile_examples enable_new_dtags largefile neon optimize_debug shared rpath debug c++11 c++14 c++1z concurrent dbus no-pkg-config reduce_exports release_tools stl
  13. Build options:
  14. Mode ................................... debug; optimized tools
  15. Optimize debug build ................... yes
  16. Building shared libraries .............. yes
  17. Using C++ standard ..................... C++1z
  18. Using ccache ........................... no
  19. Using gold linker ...................... no
  20. Using new DTAGS ........................ yes
  21. Using precompiled headers .............. no
  22. Using LTCG ............................. no
  23. Target compiler supports:
  24. NEON ................................. yes
  25. Build parts ............................ libs examples
  26. Qt modules and options:
  27. Qt Concurrent .......................... yes
  28. Qt D-Bus ............................... yes
  29. Qt D-Bus directly linked to libdbus .... no
  30. Qt Gui ................................. yes
  31. Qt Network ............................. yes
  32. Qt Sql ................................. yes
  33. Qt Testlib ............................. yes
  34. Qt Widgets ............................. yes
  35. Qt Xml ................................. yes
  36. Support enabled for:
  37. Using pkg-config ....................... no
  38. QML debugging .......................... yes
  39. udev ................................... no
  40. Using system zlib ...................... no
  41. Qt Core:
  42. DoubleConversion ....................... yes
  43. Using system DoubleConversion ........ no
  44. GLib ................................... no
  45. iconv .................................. no
  46. ICU .................................... no
  47. Logging backends:
  48. journald ............................. no
  49. syslog ............................... no
  50. slog2 ................................ no
  51. Using system PCRE2 ..................... no
  52. Qt Network:
  53. getaddrinfo() .......................... yes
  54. getifaddrs() ........................... yes
  55. IPv6 ifname ............................ yes
  56. libproxy ............................... no
  57. OpenSSL ................................ no
  58. Qt directly linked to OpenSSL ........ no
  59. SCTP ................................... no
  60. Use system proxies ..................... yes
  61. Qt Gui:
  62. Accessibility .......................... yes
  63. FreeType ............................... yes
  64. Using system FreeType ................ no
  65. HarfBuzz ............................... yes
  66. Using system HarfBuzz ................ no
  67. Fontconfig ............................. no
  68. Image formats:
  69. GIF .................................. yes
  70. ICO .................................. yes
  71. JPEG ................................. yes
  72. Using system libjpeg ............... no
  73. PNG .................................. yes
  74. Using system libpng ................ no
  75. EGL .................................... no
  76. OpenVG ................................. no
  77. OpenGL:
  78. Desktop OpenGL ....................... no
  79. OpenGL ES 2.0 ........................ no
  80. OpenGL ES 3.0 ........................ no
  81. OpenGL ES 3.1 ........................ no
  82. Session Management ..................... yes
  83. Features used by QPA backends:
  84. evdev .................................. yes
  85. libinput ............................... no
  86. INTEGRITY HID .......................... no
  87. mtdev .................................. no
  88. tslib .................................. no
  89. xkbcommon-evdev ........................ no
  90. QPA backends:
  91. DirectFB ............................... no
  92. EGLFS .................................. no
  93. LinuxFB ................................ yes
  94. VNC .................................... yes
  95. Mir client ............................. no
  96. Qt Widgets:
  97. GTK+ ................................... no
  98. Styles ................................. Fusion Windows
  99. Qt PrintSupport:
  100. CUPS ................................... no
  101. Qt Sql:
  102. DB2 (IBM) .............................. no
  103. InterBase .............................. no
  104. MySql .................................. no
  105. OCI (Oracle) ........................... no
  106. ODBC ................................... no
  107. PostgreSQL ............................. no
  108. SQLite2 ................................ no
  109. SQLite ................................. yes
  110. Using system provided SQLite ......... no
  111. TDS (Sybase) ........................... no
  112. Qt SerialBus:
  113. Socket CAN ............................. yes
  114. Socket CAN FD .......................... yes
  115. QtXmlPatterns:
  116. XML schema support ..................... yes
  117. Qt QML:
  118. QML interpreter ........................ yes
  119. QML network support .................... yes
  120. Qt Quick:
  121. Direct3D 12 ............................ no
  122. AnimatedImage item ..................... yes
  123. Canvas item ............................ yes
  124. Support for Qt Quick Designer .......... yes
  125. Flipable item .......................... yes
  126. GridView item .......................... yes
  127. ListView item .......................... yes
  128. Path support ........................... yes
  129. PathView item .......................... yes
  130. Positioner items ....................... yes
  131. ShaderEffect item ...................... yes
  132. Sprite item ............................ yes
  133. Qt Gamepad:
  134. SDL2 ................................... no
  135. Qt 3D:
  136. Assimp ................................. yes
  137. System Assimp .......................... no
  138. Output Qt3D Job traces ................. no
  139. Output Qt3D GL traces .................. no
  140. Qt 3D GeometryLoaders:
  141. Autodesk FBX ........................... no
  142. Qt Wayland Client ........................ no
  143. Qt Wayland Compositor .................... no
  144. Qt Bluetooth:
  145. BlueZ .................................. no
  146. BlueZ Low Energy ....................... no
  147. Linux Crypto API ....................... no
  148. Qt Sensors:
  149. sensorfw ............................... no
  150. Qt Quick Controls 2:
  151. Styles ................................. Default Material Universal
  152. Qt Quick Templates 2:
  153. Hover support .......................... yes
  154. Multi-touch support .................... yes
  155. Qt Positioning:
  156. Gypsy GPS Daemon ....................... no
  157. WinRT Geolocation API .................. no
  158. Qt Location:
  159. Geoservice plugins:
  160. OpenStreetMap ........................ yes
  161. HERE ................................. yes
  162. Esri ................................. yes
  163. Mapbox ............................... yes
  164. MapboxGL ............................. no
  165. Itemsoverlay ......................... yes
  166. Qt Multimedia:
  167. ALSA ................................... no
  168. GStreamer 1.0 .......................... no
  169. GStreamer 0.10 ......................... no
  170. Video for Linux ........................ yes
  171. OpenAL ................................. no
  172. PulseAudio ............................. no
  173. Resource Policy (libresourceqt5) ....... no
  174. Windows Audio Services ................. no
  175. DirectShow ............................. no
  176. Windows Media Foundation ............... no
  177. Qt WebEngine:
  178. Embedded build ......................... yes
  179. Pepper Plugins ......................... no
  180. Printing and PDF ....................... no
  181. Proprietary Codecs ..................... no
  182. Spellchecker ........................... yes
  183. WebRTC ................................. no
  184. Using system ninja ..................... no
  185. ALSA ................................... no
  186. PulseAudio ............................. no
  187. System libraries:
  188. re2 .................................. no
  189. ICU .................................. no
  190. libwebp and libwebpdemux ............. no
  191. Opus ................................. no
  192. ffmpeg ............................... no
  193. Note: Also available for Linux: linux-clang linux-icc
  194. Note: No wayland-egl support detected. Cross-toolkit compatibility disabled.
  195. Qt is now configured for building. Just run 'make'.
  196. Once everything is built, you must run 'make install'.
  197. Qt will be installed into '/opt/aarch64/qt596_64/qt_sdk'.
  198. Prior to reconfiguration, make sure you remove any leftovers from
  199. the previous build.

④执行make并重定向到makeLog.txt

命令为:make -j4 2>&1 | tee makeLog.txt

这个过程时间比较久,根据电脑性能,半个小时到六个小时不等。执行完成后的makeLog.txt如下,可以打开makeLog.txt,检索是否有error,如果没有,那就顺利编译通过啦!!!

  1. -----------------------------------------------------------------------------------------
  2. 前面省略26571行
  3. -----------------------------------------------------------------------------------------
  4. make[4]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtnetworkauth/examples/oauth/twittertimeline'
  5. make[3]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtnetworkauth/examples/oauth'
  6. make[2]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtnetworkauth/examples'
  7. make[1]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtnetworkauth'

⑤执行make install安装命令,并重定向到installLog.txt

命令为:make install 2>&1 | tee installLog.txt

installLog.txt的内容如下,打开文件检测是否有error。

  1. -------------------------------------------------------------------------------------------
  2. 前面省略13492行
  3. -------------------------------------------------------------------------------------------
  4. make[2]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qttranslations/translations'
  5. make[1]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qttranslations'
  6. cd qtdoc/ && ( test -e Makefile || /home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtbase/bin/qmake -o Makefile /home/hytera/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtdoc/qtdoc.pro ) && make -f Makefile install
  7. make[1]: Entering directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtdoc'
  8. cd doc/ && ( test -e Makefile || /home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtbase/bin/qmake -o Makefile /home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtdoc/doc/doc.pro ) && make -f Makefile install
  9. make[2]: Entering directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtdoc/doc'
  10. make[2]: Nothing to be done for 'install'.
  11. make[2]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtdoc/doc'
  12. make[1]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtdoc'

       完成这一步,qt编译成功。


4. 将qt移植到arm开发板并运行example程序

   这一部分内容较多,将在博主的另一篇博文中介绍。

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多