QT配置arm-linux-g++交叉编译器

需要准备的材料

需要准备的材料

ubuntu16.4版本虚拟机 qt5.12.9版本 ,qt-everywhere-src-5.12.9(版本要一致,没试过版本不同是否可行) (qt5.15.2 qt5.14.2都装了下,按照以下流程都是完全没错误) arm-linux-g++4.8.3版本

由于最近接手公司离职员工的代码,通常我个人都是直接写Makefile来完成,对方用的Qt配合交叉编译器使用的,由于代码太乱,还有一堆没用的源码,目录层次也太乱了,索性就按照人家的玩吧,头次琢磨这个,从网上搜的感觉像是一些培训机构里的学生把培训机构教的很固有的东西直接搬上来当教材,遇到各种问题找不到解决办法,到处翻文档总结了下。

在qt-everywhere-src-5.12.9目录下创建了个build(看个人习惯吧,也可以直接把脚本写在当前的目录),在这个目录下写了个脚本,configure.sh ,用来执行configure配置信息的。

这个配置相当关键了,之前弄了好几天,怀疑主要错误就是在这个配置不当上了

#! /bin/sh

../configure \

-prefix /home/wht/qt5.15.2-arm \

-opensource \

-confirm-license \

-release \

-xplatform linux-arm-guneabi-g++ \

-make libs \

-nomake examples \

-nomake tools \

-nomake tests \

-no-openssl \

-no-opengl \

-skip qt3d \

-skip qtactiveqt \

-skip qtandroidextras \

-skip qtcharts \

-skip qtconnectivity \

-skip qtdatavis3d \

-skip qtdeclarative \

-skip qtdoc \

-skip qtgamepad \

-skip qtimageformats \

-skip qtlocation \

-skip qtmacextras \

-skip qtmultimedia \

-skip qtnetworkauth \

-skip qtpurchasing \

-skip qtquickcontrols \

-skip qtquickcontrols2 \

-skip qtremoteobjects \

-skip qtscript \

-skip qtscxml \

-skip qtsensors \

-skip qtserialbus \

-skip qtserialport \

-skip qtspeech \

-skip qtsvg \

-skip qttools \

-skip qttranslations \

-skip qtvirtualkeyboard \

-skip qtwayland \

-skip qtwebchannel \

-skip qtwebglplugin \

-skip qtwebsockets \

-skip qtwebview \

-skip qtwinextras \

-skip qtx11extras \

-skip qtxmlpatterns

-prefix 这个配置用来生成的文件保存的目录 -xplatform 配置交叉编译器的脚本(这里要配置一个文件) -skip 都是跳过的信息 ,如果有哪些模块是自己使用的,可以删掉

要注意了 \ 换行后面不要有空格,有些人会用windows写脚本,容易发生/bin/sh^M:这个解释器的错误,如果遇到了搜搜 sed命令来解决 换行问题。

qt-everywhere-src-5.12.9/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

include(../common/linux.conf)

include(../common/gcc-base-unix.conf)

include(../common/g++-unix.conf)

# modifications to g++.conf

QMAKE_CC = arm-linux-gcc

QMAKE_CXX = arm-linux-g++

QMAKE_LINK = arm-linux-g++

QMAKE_LINK_SHLIB = arm-linux-g++

# modifications to linux.conf

QMAKE_AR = arm-linux-ar cqs

QMAKE_OBJCOPY = arm-linux-objcopy

QMAKE_NM = arm-linux-nm -P

QMAKE_STRIP = arm-linux-strip

load(qt_config)

回到build目录下执行configure.sh脚本,成功后显示 'run make’的字样,无ERROR,执行make(好多帖子使用多线程make,各种问题,就直接make吧,多线程也没节省多少时间)

如果使用其他的qt版本,遇到以下问题,直接删除这行,我这个是按照qt5.12.9版本的模块,有些版本可能模块不同,以下这个错误是当时用5.15.2版本后,直接把脚本放到5.12.9上使用,突然发现有些模块是没有的。 Project ERROR: -skip command line argument used with non-existent module ‘qtlottie’.

执行完毕没有错误,就是下面这提示,运行 make指令了,这个过程相当长了,我这公司的电脑运行了2-3小时才结束,结束没错误后,make install

由于我在执行过程中完全没遇到错误,如果看到帖子的有遇到问题的,欢迎留言。

最后一步配置QtCreator使用交叉编译器 (由于我这个当前的还没make完,所以用了之前做好了的5.15.2的做演示,添加配置都一样的) 浏览的是自己存放交叉编译器的地方,我这里是使用了arm-linux-g++的,两个都添加下。

看到蓝色的地方,就是之前-prefix 配置的目录,找到bin目录,里面有个qmake。 这里出现了个黄叹号 NO QML utility installed ,我也没整明白啥错误,也没解决,但是我试了下,可以正常编译,所以就没理这个错误。

把前面添加的qmake 和 交叉编译器路径信息添加后 OK

编译成功

参考文章

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。