美文网首页
i.mx6q 移植Qt5.6.1(含opengl)

i.mx6q 移植Qt5.6.1(含opengl)

作者: trumolong | 来源:发表于2016-08-26 11:13 被阅读0次

    (2017.8.1更新:Qt5.9.1完美移植,支持QML请看这篇:http://www.jianshu.com/p/9cc782436ece


    开发板图片

    飞凌imx6q的开发板自带的qt版本是4.8.5的,版本太老,决定移植个LTS长期支持的新版本5.6。

    新版本对qt quick的支持很完善了,所以打算项目的程序用qml来开发,这样MVC架构代码与界面可以很好的分开来,降低各个功能模块之间的耦合度。

    但qt5要支持qt quick的话就必须让Qt支持opengl,如下官网http://doc.qt.io/qt-5/embedded-linux.html 所说:

    Building Qt for a given device requires a toolchain and a sysroot. Additionally, some devices require vendor-specific adaptation code for EGL and OpenGL ES 2.0 support. This is not relevant for non-accelerated platforms, for example the ones using the LinuxFB plugin, which is meant for software-based rendering only. This means Qt Quick 2 is not functional in such a setup as it depends on OpenGL for rendering.

    还好i.mx6Q技术手册写着是支持opengl功能的。下面开始:

    1. 下载qt5.6.1源码

    到官网:
    http://download.qt.io/archive/qt/5.6/5.6.1-1/single/
    找到
    qt-everywhere-opensource-src-5.6.1-1.tar.gz
    下载最新的qt5.6.1-1源码包。

    2. 解压qt5.6.1源码

    $ tar zxvf qt-everywhere-opensource-src-5.6.1-1.tar.gz -C ~/Workspace/qt-everywhere-opensource-src-5.6.1

    解压路径自己定,后面都是按这个路径来讲解的,注意修改成你们自己的。

    3. 解压交叉编译工具链

    将飞凌提供的gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12解压到此处(路径可自己修改):

    ~/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/

    飞凌提供的百度网盘的gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12.tar 是有问题的(180M),正常是280M的,可以自行在网上按这个文件名另搜索个下载。

    4. 修改交叉编译工具到qmake.conf

    $ cd ~/Workspace/qt-everywhere-opensource-src-5.6.1
    $ vi qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf

    修改如下:

    #
    # qmake configuration for building with arm-linux-gnueabi-g++
    #
    
    MAKEFILE_GENERATOR      = UNIX
    CONFIG                 += incremental
    QMAKE_INCREMENTAL_STYLE = sublib
    
    QT_QPA_DEFAULT_PLATFORM = linuxfb   
    QMAKE_CFLAGS_RELEASE   +=-O2 -march=armv7-a
    QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv7-a
    
    include(../common/linux.conf)
    include(../common/gcc-base-unix.conf)
    include(../common/g++-unix.conf)
    
    # modifications to g++.conf
    QMAKE_CC                = arm-none-linux-gnueabi-gcc
    QMAKE_CXX               = arm-none-linux-gnueabi-g++
    QMAKE_LINK              = arm-none-linux-gnueabi-g++
    QMAKE_LINK_SHLIB        = arm-none-linux-gnueabi-g++
    
    # modifications to linux.conf
    QMAKE_AR                = arm-none-linux-gnueabi-ar cqs
    QMAKE_OBJCOPY           = arm-none-linux-gnueabi-objcopy
    QMAKE_NM                = arm-none-linux-gnueabi-nm -P
    QMAKE_STRIP             = arm-none-linux-gnueabi-strip
    
    
    QMAKE_INCDIR            += /home/volfull/Workspace/rootfs/usr/include  
    QMAKE_LIBDIR            += /home/volfull/Workspace/rootfs/usr/lib  
      
    QMAKE_LIBDIR            += /home/volfull/Workspace/rootfs/usr/lib  
      
    QMAKE_INCDIR_OPENGL_ES2 = /home/volfull/Workspace/rootfs/usr/include  
    QMAKE_LIBDIR_OPENGL_ES2 = /home/volfull/Workspace/rootfs/usr/lib  
      
    QMAKE_INCDIR_EGL = /home/volfull/Workspace/rootfs/usr/include  
    QMAKE_LIBDIR_EGL = /home/volfull/Workspace/rootfs/usr/lib  
      
    QMAKE_LIBS_OPENGL_ES1       += -lGLESv1_CM -lEGL -lGAL  
    QMAKE_LIBS_OPENGL_ES1CL     += -lGLES_CL -lEGL -lGAL  
    QMAKE_LIBS_EGL         += -lEGL  
    QMAKE_LIBS_OPENGL_ES2  += -lGLESv2 -lEGL -lGAL  
    QMAKE_LIBS_OPENVG      += -lOpenVG -lEGL -lGAL  
    #QMAKE_LIBS             += -ljpeg -ldbus-1 -lrt -lpthread    #编译选项  
    #DISTRO_OPTS += hard-float          #浮点运算使用软件不使用硬件  
      
      
    # Preferred eglfs backend  
    EGLFS_DEVICE_INTEGRATION = eglfs_viv  
    
    
    include(../common/linux_arm_device_post.conf)  
    
    load(qt_config)
    
    • 上面的配置是已经包含了opengl需要的参数;
    • /home/volfull/Workspace/rootfs/ 为飞凌开发板的文件系统,在飞凌提供的百度网盘上面可以找到;
    • arm-none-linux-gnueabi- 为飞凌提供的交叉工具链;

    5. 增加编译脚本build.sh

    $ cd ~/Workspace/qt-everywhere-opensource-src-5.6.1
    $ vi build.sh

    ./configure -release \
            -opensource -confirm-license \
            -no-c++11  \
            -no-sse2 -no-sse3 -no-ssse3 -no-sse4.1 -no-sse4.2 -no-avx -no-avx2 \
            -no-mips_dsp -no-mips_dspr2 \
        -no-opengl -opengl es2 \
            -qt-zlib -no-mtdev \
            -qt-sql-sqlite \
            -qt-libpng -qt-libjpeg -qt-freetype -qt-harfbuzz \
            -no-openssl -no-xinput2 -no-xcb-xlib -no-glib \
            -nomake examples -make libs \
            -nomake tools -nomake tests \
            -gui -widgets \
            -optimized-qmake -no-nis -no-cups -no-iconv \
            -no-tslib -no-icu -no-fontconfig -strip \
            -no-pch -no-dbus \
            -force-asserts \
            -no-xcb -no-directfb -linuxfb -no-kms \
            -qpa linux \
            -xplatform linux-arm-gnueabi-g++ \
            -libinput \
            -no-gstreamer -no-system-proxies \
            -prefix ~/qt5.6.1-1-arm -v
    
    

    chmod +x build.sh

    • -prefix ~/qt5.6.1-1-arm -v 为后面make install 时安装的路径,自行修改;

    6. 交叉编译opengl所需的库

    (1)下载 expat

    CC=arm-none-linux-gnueabi-gcc ./configure --host=arm-linux --prefix=/opt/EmbedRigol/install-dev/expat-2.1.0

    其中安装路径是 /opt/EmbedRigol/install-dev/expat-2.1.0;

    • make
    • make install
    (2)下载 libdbus.so
    • 源码的下载网址为 http://dbus.freedesktop.org/releases/dbus/ ,我这里下载 1.2.30 版本;
    • 解压在 /opt/EmbedRigol/ 文件夹下,完整路径是 /opt/EmbedRigol/dbus-1.2.30;
    • 进入源码目录,执行下面的语句进行编译配置:

    CC=arm-none-linux-gnueabi-gcc ./configure CFLAGS=-I/opt/EmbedRigol/install-dev/expat-
    2.1.0/include LDFLAGS=-L/opt/EmbedRigol/install-dev/expat-2.1.0/lib

    • make
    • make install
    • 将 /opt/EmbedRigol/install-dev/dbus-1.2.30/lib 文件夹下libdbus-1.so 相关的文件拷贝到开发板文件系统的rootfs的 lib 文件夹下;
    出错处理:
    以上2个库make install时会报错,说arm-linux-ranlib找不到;
    在它们解压源码根目录下运行: vi libtool ,找到RANLIB="arm-linux-ranlib",将其修改为(路径记得改成你们自己的):
    
    RANLIB="/home/volfull/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-none-linux-gnueabi-ranlib"
    
    

    7. 添加交叉编译工具链路径到环境变量

    $ PATH=~/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin:$PATH

    8. 交叉编译Qt

    $ cd ~/Workspace/qt-everywhere-opensource-src-5.6.1
    $ ./build.sh

    结果如下:

    
    Build options:
      Configuration .......... accessibility alsa audio-backend clock-gettime clock-monotonic compile_examples concurrent cross_compile eglfs_viv enable_new_dtags evdev eventfd force_asserts freetype full-config getaddrinfo getifaddrs harfbuzz inotify ipv6ifname large-config largefile linuxfb medium-config minimal-config mremap no-pkg-config opengl opengles2 pcre png posix_fallocate qpa qpa reduce_exports release release_tools rpath shared small-config threadsafe-cloexec zlib
      Build parts ............  libs
      Mode ................... release; optimized tools
      Using sanitizer(s)...... none
      Using C++ standard ..... c++98
      Using gold linker....... no
      Using new DTAGS ........ yes
      Using PCH .............. no
      Using LTCG ............. no
      Target compiler supports:
        Neon ................. no
    
    Qt modules and options:
      Qt D-Bus ............... no
      Qt Concurrent .......... yes
      Qt GUI ................. yes
      Qt Widgets ............. yes
      Large File ............. yes
      QML debugging .......... yes
      Use system proxies ..... no
    
    Support enabled for:
      Accessibility .......... yes
      ALSA ................... yes
      CUPS ................... no
      Evdev .................. yes
      FontConfig ............. no
      FreeType ............... qt
      Glib ................... no
      GStreamer .............. no
      GTK theme .............. no
      HarfBuzz ............... yes (bundled copy)
      Iconv .................. no
      ICU .................... no
      Image formats:
        GIF .................. yes (plugin, using bundled copy)
        JPEG ................. yes (plugin, using bundled copy)
        PNG .................. yes (in QtGui, using bundled copy)
      libinput................ no
      Logging backends:
        journald ............... no
        syslog   ............... no
      mtdev .................. no
      Networking:
        getaddrinfo .......... yes
        getifaddrs ........... yes
        IPv6 ifname .......... yes
        libproxy.............. no
        OpenSSL .............. no
      NIS .................... no
      OpenGL / OpenVG:
        EGL .................. no
        OpenGL ............... yes (OpenGL ES 2.0+)
        OpenVG ............... no
      PCRE ................... yes (bundled copy)
      pkg-config ............. no
      PulseAudio ............. no
      QPA backends:
        DirectFB ............. no
        EGLFS ................ no
          EGLFS i.MX6 ........ yes
          EGLFS i.MX6 Wayland. no
          EGLFS EGLDevice .... no
          EGLFS GBM .......... no
          EGLFS Mali ......... no
          EGLFS Raspberry Pi . no
          EGLFS X11 .......... no
        LinuxFB .............. yes
        Mir client............ no
        XCB .................. no
      Session management ..... yes
      SQL drivers:
        DB2 .................. no
        InterBase ............ no
        MySQL ................ no
        OCI .................. no
        ODBC ................. no
        PostgreSQL ........... no
        SQLite 2 ............. no
        SQLite ............... qt-qt
        TDS .................. no
      tslib .................. no
      udev ................... no
      xkbcommon-x11........... no
      xkbcommon-evdev......... no
      zlib ................... yes (bundled copy)
    
    
    NOTE: Qt is using double for qreal on this system. This is binary incompatible against Qt 5.1.
    Configure with '-qreal float' to create a build that is binary compatible with 5.1.
    
    NOTE: -optimized-tools is not useful in -release mode.
    
    Cannot read /home/volfull/Workspace/qt-everywhere-opensource-src-5.6.1/qtbase/mkspecs/common/linux_arm_device_post.conf: No such file or directory
    
            NOTICE: The -no-c++11 / --c++-level=c++98 option is deprecated.
    
            Qt 5.7 will require C++11 support. The options are in effect for this
            Qt 5.6 build, but you should update your build scripts to remove the
            option and, if necessary, upgrade your compiler.
    
    Qt is now configured for building. Just run 'make'.
    Once everything is built, you must run 'make install'.
    Qt will be installed into /home/volfull/qt5.6.1-1-arm
    
    Prior to reconfiguration, make sure you remove any leftovers from
    the previous build.
    
    

    $ make
    $ make install


    按照上面的流程下来,应该是不会出现任何问题的。make install 后即可在~/qt5.6.1-1-arm 找到编译好的qt库,将这个文件夹全部拷贝到开发板上完成qt移植工作。tslib触摸屏的库移植自行网上搜索。


    附带开发板上qt5.6.1的环境变量(QT_ROOT 是你开发板上qt5.6.1的路径):

    ##qt5.6.1-1
    export QT_ROOT=/opt/qt5.6.1-1-arm
    export PATH=$QTDIR/bin:$PATH
    export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:$QT_ROOT/lib
    export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins
    export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0
    export QT_QPA_FONTDIR=$QT_ROOT/lib/fonts
    export QML2_IMPORT_PATH=$QT_ROOT/qml
    
    

    遗留问题:


    • qt quick的相关库是编译出来了,但用qml写的程序放到开发板上运行不了,提示:
    root@freescale /home/app$ ./qml_test
    QML debugging is enabled. Only use this in a safe environment.
    jzw;pwm_backlight_update_status:s_bl_en=1
    This plugin does not support createPlatformOpenGLContext!
    Failed to create OpenGL context for format QSurfaceFormat(version 2.0, options QFlags(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples -1, swapBehavior 2, swapInterval 1, profile  0)
    Aborted
    
    

    目前还没找到解决方法,所以跑qml最后还是悲剧收场*&*,如果你们有办法的话也请告诉我一下。。。

    • qt4.8.5跑自带的demo ./fluidlauncher 2秒就起来了,qt5.6.1跑最简单自建的C++写的模板程序需要9秒才能起来,这速度够慢的。

    相关文章

      网友评论

          本文标题:i.mx6q 移植Qt5.6.1(含opengl)

          本文链接:https://www.haomeiwen.com/subject/pfbosttx.html