交叉编译Qt5.9.6中的问题及其解决

本文记录了在瑞芯微RK3399开发板上使用Qt进行界面开发遇到的问题及解决方案。面对ARMV8架构的挑战,作者详细描述了从尝试直接安装Qt到选择交叉编译的过程,分享了解决编译错误的经验,特别是如何通过调整-qreal参数成功编译Qt。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在做一个项目,需要在一块开发板上做一个界面,开发板是瑞芯微电子的RK3399,这种板子刚出时间不长,处理器是64位的ARMV8。

一开始完全不知道怎样下手,最初纠结的问题是:到底是直接在板子上安装Qt,直接在板子上开发还是在电脑上安装交叉编译环境(在电脑上开发,再移植在开发板上)。首先尝试了交叉编译,一头雾水,根本不知道怎样编译,之前做过一个在32位开发板上的小项目,尝试过交叉编译,用的是arm-linux-gcc编译器,时间过去很久了,也已经忘了,而现在是64位的板,肯定不能用arm-linux-gcc编译器了。然后又在板子上安装了Qt,用命令安装的,安装上之后根本不能用,qmake不能用,提示:No compiler can produce code for this Qt version. Please define one or more compilers.网上也找不到解决方法,只能又尝试交叉编译。

交叉编译过程:首先找了一篇博文(https://www.cnblogs.com/wanglouxiaozi/p/9521950.html)跟着文章一步步做,用的Qt版本是4.7.3,原文中说的的配置过程中用到了一个参数 -embedded armv8,意思就是嵌入式平台是ARMV8,而指定这样一个参数,会在配置完后出现一个警告:

NOTICE: Atomic operations are not yet supported for this
        architecture.

        Qt will use the 'generic' architecture instead, which uses a
        single pthread_mutex_t to protect all atomic operations. This
        implementation is the slow (but safe) fallback implementation
        for architectures Qt does not yet support.

Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into /opt/qt-4.7.3-arm64

To reconfigure, run 'make confclean' and 'configure'.

这个意思就是当前的Qt不支持这个架构(ARMV8),而博主似乎没有发现问题,而认为这是配置成功的标志,继续往下进行,也就是make,因为在ARMV8上编译Qt的文章很少,我也找不到其他的文章,于是继续跟着走,果然到了下面报错了:(作者也指出了一个可能出现的错误,但这里不是) 

 上网找了好长时间也没能找到解决办法,我想是不是Qt的版本太低,不支持ARMV8架构,就换了一个高一点的版本Qt5.6.0,又找了一篇优快云的博文(移植QT5.7.0到64位fireflyPK3399开发板),跟着文章做,编译仍然会出错误

又出现了新的问题:Project ERROR: Unknown module(s) in QT: quick,也很难解决,上网搜了很长时间没有找到什么有效的解决办法。

后来实在没有了办法,又下载了一个更高版本的Qt5.9.6,编译不出意外仍然出错,这次的错误是一个文件中的函数找不到原型:

No matching function for call to qBound(double, qreal&, double)

这个问题更难找到了,网上几乎没有,只好自己看编译过程,跟着编译报的错找到了那个文件,然而并没有找到什么有价值的信息,又上网找啊找,各种改配置文件,改一次,编译一次,从开始到报错要一个多小时,还是通不过。最后在一篇博文里发现是qreal这个参数的问题,在usr/include/qt4/Qt/qglobal.h头文件中有qreal的定义:

// This logic must match the one in qmetatype.h
#if defined(QT_COORD_TYPE)
typedef QT_COORD_TYPE qreal;
#elif defined(QT_NO_FPU) || defined(QT_ARCH_ARM) || defined(QT_ARCH_WINDOWSCE) || defined(QT_ARCH_SYMBIAN)
typedef float qreal;
#else
typedef double qreal;
#endif

在这里可以看到,如果处理器架构是ARM的,那么qreal就会被设置为float,所以在编译的时候,类型为double的数据或者函数,就会与qreal关键字不匹配了。为什么设置为float就不可以呢?目前不清楚,但我猜想是因为ARMV8是64位的架构,float是单精度占32位,double是双精度,占64位(猜想而已)。

搞清楚了这一点,就都明白了,解决方法也很简单,只要在编译时加上参数:-qreal double,即可编译通过。解决问题过程中参照的一篇博文里是将参数设置为了-qreal float,也难怪会出现问题。

### Galaxy Kylin OS Qt MySQL Development Tutorial #### Preparation of Environment To develop applications using Qt and MySQL on the Galaxy Kylin operating system, it is necessary to ensure that both environments are correctly installed. For installing MySQL drivers under Linux with QT, one can refer to a detailed blog post which provides guidance through this process[^1]. This involves ensuring compatibility between different software versions. #### Installation Steps for MySQL Driver The installation steps include downloading appropriate MySQL connector libraries compatible with the version running on the server, such as `version()` returning "8.3.0"[^3], configuring these within the project settings in Qt Creator by adding paths to `.pro` files or environment variables, and linking against them during compilation. ```bash sudo apt-get install libmysqlclient-dev qmake CONFIG+=mysql ``` These commands facilitate setting up required dependencies before integrating into projects developed via Qt framework tools like qmake. #### Handling Common Issues During Setup When encountering issues related to incomplete types while working with QApplication specifically noted under ARM64 architecture installations of Kylin systems alongside Qt, adjustments might be needed regarding how certain components interact based upon specific hardware architectures used.[^2] For problems concerning printer detection when deploying applications built from source code compiled locally versus those precompiled binaries provided directly by distributors – solutions may involve checking configuration options available inside application sources themselves along with verifying correct setup procedures were followed closely enough so no critical step was overlooked accidentally leading towards unexpected behavior observed later down line after deployment phase completed successfully but still facing some limitations not present originally at first glance over documentation alone without practical experimentation beforehand thoroughly testing all aspects involved here carefully considering every detail meticulously throughout entire process end-to-end cycle completion point reached finally achieving desired outcome expected initially planned out strategically ahead prior starting actual implementation work itself taking place now currently underway actively progressing forward steadily moving closer toward final goal achievement soon hopefully everything goes according plan smoothly without any major hiccups encountered unexpectedly causing delays potentially impacting overall timeline schedule negatively affecting progress adversely somehow someway somewhere along way eventually reaching successful conclusion ultimately. --related questions-- 1. What considerations should developers take into account when choosing between different versions of MySQL? 2. How does one configure Qt's .pro file properly to link against external databases effectively? 3. Are there alternative methods besides modifying environment variables for resolving missing library errors during build time? 4. In what scenarios would adjusting compiler flags help resolve type-related compile-time errors found in Qt programs targeting ARM platforms?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Baguenaudier

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值