Qt5.11.0交叉编译

  • 操作环境
  • 为什么交叉编译
  • 交叉编译步骤
    • 1.PC上安装Debian工具链
    • 2.PC上安装Qt5.11.0
    • 3.下载Qt源文件
      • 3.1解压
      • 3.2安装一些必要的库(如果有就安装)
      • 3.3配置qmake.conf
      • 3.4新建脚本文件
      • 3.5编译
      • 3.6测试
  • 配置Qt, 远程调试
  • 参考文献

操作环境

  • 虚拟机VitualBox,运行Debian 9.4.0
  • BeagleBone Black, 运行Debian 9.3

为什么交叉编译

You might ask, why cross compiling, why can’t I install QT creator directly on Pi and write and compile my code on it. Good question. Here are my answers:

  1. You can easily do sudo apt-get install qtcreator. But you end up developing in QT4. There is no QT5 for Pi. Trust me you don’t want to limit yourself to QT4.

  2. Raspberry Pi is a slow machine relatively. A simple build and run might takes a long time if you develop in pi itself.

  3. Your embedded device might not have head (display) or any input method. You might be developing a linux for your fridge !

交叉编译步骤

1.PC上安装Debian工具链

可以参考教程1第251~254页或教程2。教程1最终效果:

devin@debian-PC:/usr/bin$ ls arm-linux-gnueabihf*
arm-linux-gnueabihf-addr2line     arm-linux-gnueabihf-gcov-dump-6
arm-linux-gnueabihf-ar            arm-linux-gnueabihf-gcov-tool-6
arm-linux-gnueabihf-as            arm-linux-gnueabihf-gprof
arm-linux-gnueabihf-c++filt       arm-linux-gnueabihf-ld
arm-linux-gnueabihf-cpp-6         arm-linux-gnueabihf-ld.bfd
arm-linux-gnueabihf-dwp           arm-linux-gnueabihf-ld.gold
arm-linux-gnueabihf-elfedit       arm-linux-gnueabihf-nm
arm-linux-gnueabihf-g++           arm-linux-gnueabihf-objcopy
arm-linux-gnueabihf-g++-6         arm-linux-gnueabihf-objdump
arm-linux-gnueabihf-gcc           arm-linux-gnueabihf-pkg-config
arm-linux-gnueabihf-gcc-6         arm-linux-gnueabihf-ranlib
arm-linux-gnueabihf-gcc-ar-6      arm-linux-gnueabihf-readelf
arm-linux-gnueabihf-gcc-nm-6      arm-linux-gnueabihf-size
arm-linux-gnueabihf-gcc-ranlib-6  arm-linux-gnueabihf-strings
arm-linux-gnueabihf-gcov-6        arm-linux-gnueabihf-strip

arm-linux-gnueabihf-g++ (Debian 6.3.0-18) 6.3.0 20170516
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

2.PC上安装Qt5.11.0

在此网站下载Linux系统安装包并安装。

3.下载Qt源文件

Qt5.11.0源文件:http://download.qt.io/official_releases/qt/5.11/5.11.0/single/qt-everywhere-src-5.11.0.tar.xz

3.1解压

tar --help

3.2安装一些必要的库(如果有就安装)

  • 参考链接1
sudo apt-get install libx11-dev libavahi-gobject-dev libSM-dev 
libfontconfig-dev libXext-dev libfontconfig1-dev libfreetype6-dev libx11-dev 
libxcursor-dev libxfixes-dev libxft-dev libxi-dev libxrandr-dev libxrender-dev
  • 参考链接2
QT4 only
 libxcursor-dev
 libxft-dev
 libxrandr-dev
 libx11-dev
 -------------------
QT4&5
 libfreetype6-dev        
 libfontconfig1-dev
 libxext-dev
 libxfixes-dev
 libxrender-dev
 libxi-dev

 -------------------
QT5 only
 libxkbcommon-dev

 libxcb1-dev
 libx11-xcb-dev
 libxcb-glx0-dev
 libxcb-keysyms1-dev
 libxcb-image0-dev
 libxcb-shm0-dev
 libxcb-icccm4-dev
 libxcb-sync0-dev
 libxcb-xfixes0-dev
 libxcb-shape0-dev
 libxcb-randr0-dev
 libxcb-render-util0-dev
  • 参考链接3
sudo apt-get upgrade
sudo apt-get update
sudo apt-get install libgl1-mesa-dev
up to here should be fine. If you got more errors, keep going:

sudo apt-get build-dep qt5-default
sudo apt-get install libxcb-xinerama0-dev
sudo apt-add-repository ppa:u-szeged/sedkit
sudo apt-get update
sudo apt-get install sedkit-env-qtwebkit
sudo apt-get install build-essential perl python git
sudo apt-get install “^libxcb.*” libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev
sudo apt-get install flex bison gperf libicu-dev libxslt-dev ruby
sudo apt-get install libssl-dev libxcursor-dev libxcomposite-dev libxdamage-dev libxrandr-dev libfontconfig1-dev libcap-dev libxtst-dev libpulse-dev libudev-dev libpci-dev libnss3-dev libasound2-dev libxss-dev libegl1-mesa-dev gperf bison
sudo apt-get install libbz2-dev libgcrypt11-dev libdrm-dev libcups2-dev libatkmm-1.6-dev
sudo apt-get install libasound2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev

3.3配置qmake.conf

cp -r linux-beagleboard-g++/ linux-beagleboneblack-g++
sudo vim qmake.conf
其中qmake.conf有两行未测试,如若不能运行再删除.

devin@debian-PC:~/qt-src/qt-everywhere-src-5.11.0/qtbase/mkspecs/devices$ ls
common                           linux-jetson-tk1-g++
freebsd-generic-clang            linux-jetson-tk1-pro-g++
freebsd-rasp-pi-clang            linux-jetson-tx1-g++
integrity-armv8-drive-cx         linux-mipsel-broadcom-97425-g++
integrity-armv8-msm8996au        linux-mipsel-ci20-g++
linux-archos-gen8-g++            linux-nuc-g++
linux-arm-amlogic-8726M-g++      linux-odroid-xu3-g++
linux-arm-generic-g++            linux-rasp-pi2-g++
linux-arm-hisilicon-hix5hd2-g++  linux-rasp-pi3-g++
linux-arm-trident-pnx8473-g++    linux-rasp-pi3-vc4-g++
linux-BBB-g++                    linux-rasp-pi-g++
linux-beagleboard-g++            linux-rcar-h2-g++
linux-colibri-vf-g++             linux-rcar-m3-g++
linux-drive-cx-g++               linux-sh4-stmicro-ST7108-g++
linux-emu-g++                    linux-sh4-stmicro-ST7540-g++
linux-generic-g++                linux-snowball-g++
linux-imx53qsb-g++               linux-tegra2-g++
linux-imx6-g++                   linux-tinkerboard-g++
linux-imx7-g++

devin@debian-PC:~/qt-src/qt-everywhere-src-5.11.0/qtbase/mkspecs/devices$ cp -r linux-beagleboard-g++/ linux-beagleboneblack-g++

devin@debian-PC:~/qt-src/qt-everywhere-src-5.11.0/qtbase/mkspecs/devices$ cd linux-beagleboneblack-g++/

devin@debian-PC:~/qt-src/qt-everywhere-src-5.11.0/qtbase/mkspecs/devices/linux-beagleboneblack-g++$ ls
qmake.conf  qplatformdefs.h

devin@debian-PC:~/qt-src/qt-everywhere-src-5.11.0/qtbase/mkspecs/devices/linux-beagleboneblack-g++$ vim qmake.conf
=======================================================================
devin@debian-PC:~/qt-src/qt-everywhere-src-5.11.0/qtbase/mkspecs/devices/linux-beagleboneblack-g++$ more qmake.conf 
#
# qmake configuration for the BeagleBoard and BeagleBoard xM boards
# http://beagleboard.org/

MAKEFILE_GENERATOR      = UNIX
CONFIG                 += incremental
QMAKE_INCREMENTAL_STYLE = sublib


#CONFIG=...和QT=...两行未经测试
#CONFIG                 += qt warn_on release incremental link_prl gdb_dwarf_index
#QT                     += core gui


include(../../common/linux.conf)
include(../../common/gcc-base-unix.conf)
include(../../common/g++-unix.conf)

load(device_config)

QT_QPA_DEFAULT_PLATFORM = eglfs

# modifications to g++.conf
QMAKE_CC                = $${CROSS_COMPILE}gcc
QMAKE_CXX               = $${CROSS_COMPILE}g++
QMAKE_LINK              = $${QMAKE_CXX}
QMAKE_LINK_SHLIB        = $${QMAKE_CXX}

# modifications to linux.conf
QMAKE_AR                = $${CROSS_COMPILE}ar cqs
QMAKE_OBJCOPY           = $${CROSS_COMPILE}objcopy
QMAKE_NM                = $${CROSS_COMPILE}nm -P
QMAKE_STRIP             = $${CROSS_COMPILE}strip

COMPILER_FLAGS          = -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mthumb

#modifications to gcc-base.conf
QMAKE_CFLAGS           += $${COMPILER_FLAGS}
QMAKE_CXXFLAGS         += $${COMPILER_FLAGS}
QMAKE_CXXFLAGS_RELEASE += -O3

QMAKE_LIBS             += -lrt -lpthread -ldl

# Extra stuff (OpenGL, DirectFB, ...)
QMAKE_INCDIR_EGL        =
QMAKE_LIBDIR_EGL        =
QMAKE_INCDIR_OPENGL_ES2 = $${QMAKE_INCDIR_EGL}
QMAKE_LIBDIR_OPENGL_ES2 = $${QMAKE_LIBDIR_EGL}
QMAKE_INCDIR_OPENVG     = $${QMAKE_INCDIR_EGL}
QMAKE_LIBDIR_OPENVG     = $${QMAKE_LIBDIR_EGL}

QMAKE_LIBS_EGL          = -lEGL -lIMGegl -lsrv_um
QMAKE_LIBS_OPENGL_ES2   = -lGLESv2 $${QMAKE_LIBS_EGL}
QMAKE_LIBS_OPENVG       = -lOpenVG $${QMAKE_LIBS_EGL}

DISTRO_OPTS += hard-float

# No need for any special EGL device integration.
# Prioritize the default, compiled-in integration over any plugins.
EGLFS_DEVICE_INTEGRATION = none

include(../common/linux_arm_device_post.conf)

load(qt_config)

3.4新建脚本文件

CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf-
其中 /usr/bin/ 目录已安装有arm-linux-gnueabihf-g++和arm-linux-gnueabihf-gcc等编译器。

devin@debian-PC:~/qt-src/qt-everywhere-src-5.11.0$ sudo more cfg_beagleboneblack.sh 
#!/bin/sh

./configure  \
-v  \
-opensource  \
-confirm-license  \
-release  \
-prefix  /opt/qt5.11.0-armhf   \
-device linux-beagleboneblack-g++  \
-device-option CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf-  \
-qt-libpng  \
-qt-libjpeg  \
-linuxfb  \
-no-opengl  \
-nomake examples  \
-no-feature-accessibility

3.5编译

devin@debian-PC:~/qt-src/qt-everywhere-src-5.11.0$ make
...
...
devin@debian-PC:~/qt-src/qt-everywhere-src-5.11.0$ sudo make install
...
...

3.6测试


PC上:

  • sudo vim main.cpp
  • $QMAKE_DIR/qmake -project
  • $QMAKE_DIR/qmake
  • make
  • sftp [email protected]
  • put testproject

Beaglebone上:

  • ./testproject

编译时出现找不到头文件的错误时,看一下testproject.pro里有没有一下两行:

INCLUDEPATH += /usr/loacl/qt5.11.0-armhf/include #交叉编译文件头文件目录
INCLUDEPATH += /opt/Qt5.11.0/5.11.0/gcc_64/include #Qt5.11.0安装目录头文件
QT += core gui widgets

配置Qt, 远程调试

  • 远程部署和调试
  • https://blog.csdn.net/hechao3225/article/details/52981148

参考文献

1.http://doc.qt.io/qt-5/embedded-linux.html
2.http://exploringbeaglebone.com/chapter11/
3.https://www.kancloud.cn/lichee/lpi0/418898
4.http://m-embedded.blogspot.com/2015/08/build-qt5-for-beaglebone-balck.html
5.https://medium.com/@amirmann/how-to-cross-compile-qt-for-raspberry-pi-3-on-linux-ubuntu-for-beginners-75acf2a078c
6.https://wiki.qt.io/Building_Qt_for_Embedded_Linux
7.https://gist.github.com/fm4dd/c663217935dc17f0fc73c9c81b0aa845

你可能感兴趣的:(BeagleBone)