Windows平台交叉编译Arm Linux平台的QT5.7库

1、准备交叉编译环境

环境说明:Windows 7 64位
此过程需要:
(1)Qt库开源代码,我使用的是5.7.0版本;
(2)Perl语言环境5.12版本以上;
(3)Python语言环境 2.7 版本以上;
(4)Windows平台上的MinGW开发工具集(内含本地编译器gcc、g++ 4.9以上版本,支持c++11);
(5)Windows平台上的交叉编译器arm-linux-gnueabihf(gcc、g++4.9以上版本,支持c++11)。

1.1、下载Qt库源代码

到Qt官网官网 https://www.qt.io/download-open-source/#section-2 下载qt-everywhere-opensource-src-5.7.0.zip或者qt-everywhere-opensource-src-5.7.0.tar.gz。

1.2、安装Perl

到Perl官网 https://www.perl.org/get.html 下载ActivePerl 5.12以上版本,如ActivePerl-5.24.0.2400-MSWin32-x86-64int-300560.exe。安装完成后将安装目录里的bin目录路径添加到windows环境变量的PATH中。

1.3、安装Python

到Python官网 https://www.python.org/downloads/ 下载Python2.7以上版本,如python-3.5.2.exe。安装完成后将安装目录里的bin目录路径添加到windows环境变量的PATH中。

1.4、MinGW开发工具集

MinGW工具集内含编译器工具gcc、g++等,需要此工具集来编译Qt的qmake等开发工具,因为qmake这些开发工具是在本地windows上运行的。要求4.9以上版本的gcc、g++,4.8以上就已经支持c++11。
32位系统可以到 https://sourceforge.net/projects/mingw/ 下载mingw-get-setup.exe后进行在线安装;64位系统到 https://sourceforge.net/projects/mingw-w64/ 下载mingw-w64-install.exe后进行在线安装。安装完成后将其bin目录添加到环境变量PATH中。

1.5、安装交叉编译器

之前使用的Codesourcery公司的交叉编译器版本较低(arm-2014.05-29-arm-none-linux-gnueabi.exe,arm-none-linux-gnueabi,gcc 4.8.3),支持c++11不完全,而且编译好的程序需要联带几个基础的依赖库一起打包,麻烦了点。
现使用linaro公司的交叉编译器,可到 http://releases.linaro.org/14.07/components/toolchain/binaries/ 下载gcc-linaro-arm-linux-gnueabihf-4.9-2014.07-20140726_win32.exe,安装完成后,将其bin目录添加到环境变量PATH中。arm-linux-gnueabihf工具编译后的程序不需要联带依赖库一起打包。

2、交叉编译Qt库

2.1、编译前的处理

解压Qt源码到本地。用文本方式打开Qt源码目录里qtbase\mkspecs\linux-arm-gnueabi-g++\ qmake.conf配置文件,修改交叉编译器程序名相关的配置。
在这里插入图片描述
修改后:
在这里插入图片描述
编译发现一个链接错误,查找其原因是有一个源文件没有被编译,挺奇怪的。解决办法是修改qtbase\src\corelib\kernel\kernel.pri文件,貌似qpoll.cpp编译条件没达到,改为强制编译。
修改前:
在这里插入图片描述
修改后
在这里插入图片描述

2.2、编译之configure

打开cmd窗口,进入Qt源码目录,执行如下代码,然后输入y接受许可协议开始配置,等待配置完成。

 configure.bat -release -opensource -prefix D:\Qt5.7.0_ARM_Linux -nomake tests -nomake examples -no-opengl -skip qtvirtualkeyboard  -xplatform linux-arm-gnueabi-g++

注:命令中,
-release:编译release版本。
-opensource:表示开源许可;
-prefix:指定安装目录,根据自己喜好;安装后qmake程序默认就会根据这个目录路径去搜索头文件和库文件,
-nomake:表示不编译后面参数指定的模块;
-no-opengl:表示不编译OpenGL,这个我们用不着,也没有安装OpenGL环境,所以不编译,否则会出错;
–skip qtvirtualkeyboard:跳过qtvirtualkeyboard,没有相应库环境,不编译,否则编译和安装过程中可能会报错。
-xplatform linux-arm-gnueabi-g++:指定交叉编译器配置目录为linux-arm-gnueabi-g++,qmake会到qtbase\mkspecs\linux-arm-gnueabi-g++里读取qmake.conf文件,找到交叉编译工具来编译Qt动态库。

默认-shared:编译动态库
默认-platform:为win32-g++,即指定本地编译器配置目录,到qtbase\mkspecs\ win32-g++目录里读取qmake.conf文件,找到本地编译工具来编译qmake。

2.3、编译之make

Configure正常完成后,执行命令mingw32-make开始编译。

2.4、编译之make install

编译完成后,执行mingw32-make install命令开始安装,将会安装把之前-prefix指定的目录中。
注:qmake默认都是以-prefix指定的绝对目录去搜索头文件和库文件,所以qmake本身可以移动变更路径;但如果是整个Qt库目录路径都变更,则需要在qmake.exe程序所在目录增加一个qt.conf配置文件,文件内容为:

[Paths]
Prefix=..

即用配置文件qt.conf里的Prefix项去更改qmake搜索的库路径,上面是一般情况情况即整个库目录被移动后时的配置方式,即以父目录为库路径。

3、安装与配置Qt Creator

到Qt官网官网 https://www.qt.io/download-open-source/#section-2 下载独立的Qt Creator程序安装包qt-creator-opensource-windows-x86-4.1.0.exe来安装。Qt Creator安装程序本身不大,因为不含有qmake等工具,也不含有Qt库。
也可以下载windows平台的Qt整包qt-opensource-windows-x86-mingw530-5.7.0.exe来安装,里面包含有Qt Creator、windows-x86 Qt库、mingw5.3.0。所以如果使用这个安装包,之前可以不用单独安装MinGW。安装此包后可以开发本地的Qt程序,经过如下的配置后还可以开发ARM linux程序。
不论使用上述哪个包安装,都需要按如下配置好上面编译好的Qt库才能编译ARM linux平台的Qt程序。
启动运行Qt Creator,菜单工具(Tools)->选项(options),打开设置对话框,切换到构建与运行(build and run)项。先添加交叉编译器,点击添加,找到交叉编译器路径,取个名称,如下图。
在这里插入图片描述
设置make路径:点击Add,找到minGW安装目录bin里的mingw32-make.exe,取个名后添加,如下图。
在这里插入图片描述
如果需要用到调试功能,设置调试器Debugger与上类似。
设置Qt版本,点击添加,找到Qt库安装目录bin里的qmake.exe,取个名后添加,如下图
在这里插入图片描述
最后整合整套工具,设置构建套件,如下图,点击添加,取个名称,选择之前设置好的交叉编译器和Qt版本,点击Apply。最终点击”设置为默认”将该套方案作为当前编译方案。
在这里插入图片描述
至此,可以开发ARM linux上的Qt程序了。

Building on: linux-g++ (x86_64, CPU features: mmx sse sse2) Building for: linux-aarch64-gnu-g++ (arm64, CPU features: neon) Target compiler: gcc 6.3.1 Configuration: cross_compile use_gold_linker compile_examples enable_new_dtags largefile neon precompile_header shared rpath release c++11 c++14 concurrent dbus reduce_exports stl Build options: Mode ................................... release Optimize release build for size ........ no Building shared libraries .............. yes Using C standard ....................... C11 Using C++ standard ..................... C++14 Using ccache ........................... no Using gold linker ...................... yes Using new DTAGS ........................ yes Using precompiled headers .............. yes Using LTCG ............................. no Target compiler supports: NEON ................................. yes Build parts ............................ libs Qt modules and options: Qt Concurrent .......................... yes Qt D-Bus ............................... yes Qt D-Bus directly linked to libdbus .... no Qt Gui ................................. yes Qt Network ............................. yes Qt Sql ................................. yes Qt Testlib ............................. yes Qt Widgets ............................. yes Qt Xml ................................. yes Support enabled for: Using pkg-config ....................... yes udev ................................... no Using system zlib ...................... yes Qt Core: DoubleConversion ....................... yes Using system DoubleConversion ........ no GLib ................................... no iconv .................................. yes ICU .................................... no Tracing backend ........................ Logging backends: journald ............................. no syslog ............................... no slog2 ................................ no Using system PCRE2 ..................... no Qt Network: getifaddrs() ........................... yes IPv6 ifname ............................ yes libproxy ............................... no Linux AF_NETLINK ....................... yes OpenSSL ................................ yes Qt directly linked to OpenSSL ........ no OpenSSL 1.1 ............................ no DTLS ................................... yes SCTP ................................... no Use system proxies ..................... yes Qt Gui: Accessibility .......................... yes FreeType ............................... yes Using system FreeType ................ no HarfBuzz ............................... yes Using system HarfBuzz ................ no Fontconfig ............................. no Image formats: GIF .................................. yes ICO .................................. yes JPEG ................................. yes Using system libjpeg ............... yes PNG .................................. yes Using system libpng ................ no EGL .................................... no OpenVG ................................. no OpenGL: Desktop OpenGL ....................... no OpenGL ES 2.0 ........................ no OpenGL ES 3.0 ........................ no OpenGL ES 3.1 ........................ no OpenGL ES 3.2 ........................ no Vulkan ................................. no Session Management ..................... yes Features used by QPA backends: evdev .................................. yes libinput ............................... no INTEGRITY HID .......................... no mtdev .................................. no tslib .................................. no xkbcommon .............................. no X11 specific: XLib ................................. no EGL on X11 ........................... no QPA backends: DirectFB ............................... no EGLFS .................................. no LinuxFB ................................ yes VNC .................................... yes Mir client ............................. no Qt Sql: SQL item models ........................ yes Qt Widgets: GTK+ ................................... no Styles ................................. Fusion Windows Qt PrintSupport: CUPS ................................... no Qt Sql Drivers: DB2 (IBM) .............................. no InterBase .............................. no MySql .................................. no OCI (Oracle) ........................... no ODBC ................................... no PostgreSQL ............................. no SQLite2 ................................ no SQLite ................................. yes Using system provided SQLite ......... no TDS (Sybase) ........................... no Qt Testlib: Tester for item models ................. yes Qt SerialBus: Socket CAN ............................. yes Socket CAN FD .......................... yes Qt QML: QML network support .................... yes QML debugging and profiling support .... yes QML sequence object .................... yes QML list model ......................... yes QML XML http request ................... yes QML Locale ............................. yes QML delegate model ..................... yes Qt Quick: Direct3D 12 ............................ no AnimatedImage item ..................... yes Canvas item ............................ yes Support for Qt Quick Designer .......... yes Flipable item .......................... yes GridView item .......................... yes ListView item .......................... yes TableView item ......................... yes Path support ........................... yes PathView item .......................... yes Positioner items ....................... yes Repeater item .......................... yes ShaderEffect item ...................... yes Sprite item ............................ yes Qt Scxml: ECMAScript data model for QtScxml ...... yes Qt Gamepad: SDL2 ................................... no Qt 3D: Assimp ................................. yes System Assimp .......................... no Output Qt3D Job traces ................. no Output Qt3D GL traces .................. no Use SSE2 instructions .................. no Use AVX2 instructions .................. no Aspects: Render aspect ........................ yes Input aspect ......................... yes Logic aspect ......................... yes Animation aspect ..................... yes Extras aspect ........................ yes Qt 3D Renderers: OpenGL Renderer ........................ yes Qt 3D GeometryLoaders: Autodesk FBX ........................... no Qt Wayland Client ........................ no Qt Wayland Compositor .................... no Qt Bluetooth: BlueZ .................................. no BlueZ Low Energy ....................... no Linux Crypto API ....................... no WinRT Bluetooth API (desktop & UWP) .... no Qt Sensors: sensorfw ............................... no Qt Quick Controls 2: Styles ................................. Default Fusion Imagine Material Universal Qt Quick Templates 2: Hover support .......................... yes Multi-touch support .................... yes Qt Positioning: Gypsy GPS Daemon ....................... no WinRT Geolocation API .................. no Qt Location: Qt.labs.location experimental QML plugin . yes Geoservice plugins: OpenStreetMap ........................ yes HERE ................................. yes Esri ................................. yes Mapbox ............................... yes MapboxGL ............................. no Itemsoverlay ......................... yes QtXmlPatterns: XML schema support ..................... yes Qt Multimedia: ALSA ................................... no GStreamer 1.0 .......................... no GStreamer 0.10 ......................... no Video for Linux ........................ yes OpenAL ................................. no PulseAudio ............................. no Resource Policy (libresourceqt5) ....... no Windows Audio Services ................. no DirectShow ............................. no Windows Media Foundation ............... no Qt Tools: QDoc ................................... no Qt WebEngine: Embedded build ......................... yes Pepper Plugins ......................... no Printing and PDF ....................... no Proprietary Codecs ..................... no Spellchecker ........................... yes Native Spellchecker .................... no WebRTC ................................. no Use System Ninja ....................... no Geolocation ............................ yes WebChannel support ..................... yes Use v8 snapshot ........................ yes Kerberos Authentication ................ no Building v8 snapshot supported ......... yes Use ALSA ............................... no Use PulseAudio ......................... no Optional system libraries used: re2 .................................. no icu .................................. no libwebp, libwebpmux and libwebpdemux . no opus ................................. no ffmpeg ............................... no libvpx ............................... no snappy ............................... no glib ................................. no zlib ................................. yes minizip .............................. no libevent ............................. no jsoncpp .............................. no protobuf ............................. no libxml2 and libxslt .................. no lcms2 ................................ no png .................................. no JPEG ................................. no harfbuzz ............................. no freetype ............................. no x11 .................................. no Required system libraries: fontconfig ........................... no dbus ................................. no nss .................................. no khr .................................. no glibc ................................ yes Required system libraries for qpa-xcb: libdrm ............................... no xcomposite ........................... no xcursor .............................. no xi ................................... no xrandr ............................... no xtst ................................. no Note: Also available for Linux: linux-clang linux-icc
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值