本篇内容主要讲解“QT5交叉编译怎么实现”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“QT5交叉编译怎么实现”吧!
./configure -release -opensource -prefix <path> -no-largefile -no-pkg-config -no-qml-debug -xplatform <target> -qt-libpng -qt-zlib -qt-libjpeg -qt-freetype -qt-sql-sqlite -plugin-sql-sqlite -no-harfbuzz -no-openssl -no-libproxy -make libs -nomake tests -nomake examples -gui -widgets -no-cups -no-tslib -iconv -pch -no-c++11
在qtbase/mkspecs/目录下根据相近的平台创建对应的目标工具编译配置目录,如参考目录下的linux-arm-gnueabi-g++创建
The Qt Platform Abstraction (QPA) is the platform abstraction layer for Qt 5 and replaces Qt for Embedded Linux and the platform ports from Qt 4.
QT_QPA_DEFAULT_PLATFORM = linuxfb QMAKE_CFLAGS_RELEASE += -O2 -march=armv5te QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv5te
QT_QPA_DEFAULT_PLATFORM是必须的,通常在mac上是cocoa,在window上是windows,在linuxX11下是xcb,如果有OPENGL支持,那么选eglfs. 对于无硬件加速的设备,选择linuxfb,minimal仅仅是让程序跑通,不起任何作用(看不到界面).QPA是QT Platform Abstraction的缩写.
tslib代表QT对触摸板的支持,需要额外添加tslib库的链接,-I 和L后面分别为为第一步编译tslib的include和lib的安装目录。
Qt5.7的版本连编译的时候都要gcc编译器支持c++11才能通过configure。
-c++std <edition> .. Compile Qt with C++ standard edition (c++11, c++14, c++1z) Default: highest supported
Qt5.6.2及以前的版本通过添加-no-c++11的配置项,可以用c++98编译,提示:
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.
make -j4 module-qtbase
问题一:error :expected initializer before “throw”
上面这个问题我自己解决了,在主机目录 /usr/include/i386-linux-gnu/sys/signalfd.h 文件中 signalfd 定义如下
extern int signalfd (int __fd, const sigset_t *__mask, int __flags) __THROW __nonnull ((2));
而海思交叉编译工具目录下 signalfd.h 文件中 signalfd 定义如下
extern int signalfd (int __fd, const sigset_t *__mask, int __flags) __nonnull ((2)) __THROW;
把 __nonnull ((2)) 和 __THROW 前后调换一下就可以了。
QPA插件编译
目录:qtbase/src/plugins/platforms 库文件:qtbase/plugins/platforms/
问题一:QT_QPA_DEFAULT_PLATFORM = linux #eglfs
# ./basiclayouts This application failed to start because it could not find or load the Qt platform plugin "linux #eglfs" in "". Reinstalling the application may fix this problem. Aborted
修改QT_QPA_DEFAULT_PLATFORM的值为linuxfb,拷贝插件libqlinuxfb.so到开发机器上。问题仍然出现,解决办法:设置相应的环境变量。
export QT_PLUGIN_PATH=/mnt/3520d/qt5.6.2/plugins
将qtbase/src/plugins/platforms目录内容(整个目录)都拷贝到环境变量指定的目录下面。
问题二:字体文件
# ./basiclayouts QFontDatabase: Cannot find font directory /home/lzh/qt/qt-everywhere-opensource-src-5.6.2/hi3520d-uclibc/lib/fonts - is Qt installed correctly? QFontDatabase: Cannot find font directory /home/lzh/qt/qt-everywhere-opensource-src-5.6.2/hi3520d-uclibc/lib/fonts - is Qt installed correctly? QFontDatabase: Cannot find font directory /home/lzh/qt/qt-everywhere-opensource-src-5.6.2/hi3520d-uclibc/lib/fonts - is Qt installed correctly? QFontDatabase: Cannot find font directory /home/lzh/qt/qt-everywhere-opensource-src-5.6.2/hi3520d-uclibc/lib/fonts - is Qt installed correctly?
解决办法:设置字体环境变量
export QT_QPA_FONTDIR=/mnt/3520d/qt5.6.2/lib/fonts
Qt normally uses fontconfig to provide access to system fonts. If fontconfig is not available, Qt will fall back to using QBasicFontDatabase. In this case, Qt applications will look for fonts in Qt's lib/fonts directory. Qt will automatically detect pre-rendered fonts and TrueType fonts. This directory can be overridden by setting the QT_QPA_FONTDIR environment variable.
可以通过设置QT_QPA_PLATFORM环境变量或者是在命令行指定 -platform 选项来选择响应的显示插件(eglfs, xcb, linuxfb等).
export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb1
linuxfb自带libinput支持,只需要设置环境变量就好了。
export QT_QPA_EVDEV_MOUSE_PARAMETERS="usb:/dev/event0"
支持热插拔需要构建的QT支持libudev:
Hot plugging is supported, but only if Qt was configured with libudev support (that is, if the libudev development headers are present in the sysroot at configure time). This allows connecting or disconnecting an input device while the application is running.
export QT_QPA_EVDEV_KEYBOARD_PARAMETERS="usb:/dev/event3"
PNG与JPEG格式图片的支持,在构建QT时需要配置相应的选项:
PNG: -qt-libpng, QT5自带支持 JPG:-qt-libjpeg, 需要编译插件支持
对于JPEG的支持,除了增加构建选项外,还需要将对应的jpeg插件拷贝到设备上去,才能正确地处理图片。
图像插件代码目录在:qtbase/src/plugins/imageformats
构建成功的插件库位置在:qtbase/plugins/imageformats
将imageformats目录拷贝到设备上,同时设置QT的插件路径环境变量,与前面的QPA插件一致。
export QT_PLUGIN_PATH=/mnt/3520d/qt5.6.2/plugins
此外,JPEG图片不支持透明度功能。
到此,相信大家对“QT5交叉编译怎么实现”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。