嵌入式linux 编译qt5(以v851s为例)

发布时间:2024年01月12日

本文参考Blev大神的博客:Yuzuki Lizard V851S开发板 --移植 QT5.12.9教程(群友Blev提供) - Allwinner / 柚木PI-V851S - 嵌入式开发问答社区 (100ask.net)

一. 环境准备?

1.下载qt5源码:Open Source Development | Open Source License | Qt?或者从v851s sdk 中获取

路径:tina-v853-docker/platform/thirdparty/gui/qt/qt-5.12.9.tar.xz

2. 编译环境:vmware虚拟机安装的ubuntu22.10

3. 交叉编译工具:v851s sdk 中的toolchain

路径:tina-v853-docker/prebuilt/rootfsbuilt/arm/toolchain-sunxi-musl-gcc-830

4. ubuntu下需要安装的依赖库:

apt-get install repo git gcc-arm-linux-gnueabihf u-boot-tools device-tree-compiler mtools \
parted libudev-dev libusb-1.0-0-dev python-linaro-image-tools linaro-image-tools libssl-dev \
autotools-dev libsigsegv2 m4 libdrm-dev curl sed make binutils build-essential gcc g++ bash \
patch gzip bzip2 perl tar cpio python unzip rsync file bc wget libncurses5 libglib2.0-dev \
openssh-client lib32stdc++6 gcc-aarch64-linux-gnu libncurses5-dev lzop libssl1.0.0 libssl-dev \
libglade2-dev cvs mercurial subversion asciidoc w3m dblatex graphviz python-matplotlib \
libc6:i386 texinfo liblz4-tool genext2fs expect autoconf intltool libqt4-dev libgtk2.0-dev

二. 解压qt5源码进行编译

1. 在 ubuntu 的 home/xxx/ 下创建一个qt5 的文件,解压qt5 源码

tar -xvf qt-xxx.tar.xz

2. 将交叉编译工具放到 ubuntu 的home/xxx/? ,采用绝对路径的方式调用交叉编译工具

3. 在qt5 源码根目录下创建 build.sh 写入编译规则?,并且给权限

touch build.sh
chmod 777 build.sh

在 build.sh 中写入编译规则:

#!/bin/sh
PWD=`pwd`
    mkdir arm-qt
    ./configure \
    -prefix $PWD/arm-qt \
    -release \
    -opensource \
    -shared \
    -xplatform linux-arm-gnueabi-g++ \
    -optimized-qmake \
    -pch \
    -qt-sqlite \
    -qt-libjpeg \
    -qt-libpng \
    -qt-zlib \
    -no-opengl \
    -skip qt3d \
    -skip qtcanvas3d \
    -skip qtpurchasing \
    -skip qtlocation \
    -skip qttools \
    -no-sse2 \
    -no-openssl \
    -no-cups \
    -no-glib \
    -no-dbus \
    -no-xcb \
    -no-iconv \
    -no-separate-debug-info \
    -no-fontconfig \
    -recheck-all \
    -make examples

    make -j16 
    make install

4. 配置交叉编译工具路径,qt5源码根目录下打开文件qmake.conf:

gedit 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)

#一定要是你 toolchain 的绝对路径,不要写错
#CROSS_COMPILE=arm-openwrt-linux
#CROSS_COMPILE=/home/navy/v851s/Yuzukilizard/toolchain/toolchain-sunxi-musl-gcc-830/toolchain/bin/arm-openwrt-linux
CROSS_COMPILE=/home/navy/v851s/Yuzukilizard/toolchain/gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi

# modifications to g++.conf
QMAKE_CC                = $${CROSS_COMPILE}-gcc
QMAKE_CXX               = $${CROSS_COMPILE}-g++
QMAKE_LINK              = $${CROSS_COMPILE}-g++
QMAKE_LINK_SHLIB        = $${CROSS_COMPILE}-g++

# modifications to linux.conf
QMAKE_AR                = $${CROSS_COMPILE}-ar cqs
QMAKE_OBJCOPY           = $${CROSS_COMPILE}-objcopy
QMAKE_NM                = $${CROSS_COMPILE}-nm -P
QMAKE_STRIP             = $${CROSS_COMPILE}-strip
load(qt_config)

5. 编译并安装产生库文件

??在qt5 源码根目录下执行:

./build.sh

? 执行:

make install

? 将会在qt5 根目录arm-qt 文件中产生所有的qt5 的库文件,将其下载到嵌入式开发版中即可。

三. 编写qtDemo 进行测试

1. 在 ubuntu home/xxx/?中创建qtDemo 文件夹,并且创建两个文件helloworld.cpp 和 helloworld.pro?

mkdir qtDemo
touch helloworld.cpp
touch helloworld.pro

在 helloworld.cpp 中写入:

#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QSlider>
#include <QHBoxLayout>
 
int main(int argc, char **argv)
{
	 QApplication app(argc, argv);
	 QWidget *window  = new QWidget;
	 window->setWindowTitle("I am a slider");
	 
	 QLabel *label = new QLabel;  // QLabel控件,用于显示数字
	 QSlider *slider = new QSlider(Qt::Horizontal);  // 滑动条
	 slider->setRange(0, 100);
	 
	 QObject::connect(slider, SIGNAL(valueChanged(int)), label, SLOT(setNum(int)));
	 slider->setValue(50);
	 
	 QHBoxLayout *layout = new QHBoxLayout; //level 
	 layout->addWidget(label);
	 layout->addWidget(slider);
	 window->setLayout(layout);
	 
	 window->resize(400, 240);
	 
	 window->show();
	 
	 return app.exec();
}

在 helloworld.pro 中写入:

######################################################################
# Automatically generated by qmake (3.1) Fri Jan 12 17:28:28 2024
######################################################################

TEMPLATE = app
TARGET = helloworld
INCLUDEPATH += .

# The following define makes your compiler warn you if you use any
# feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

# Input
SOURCES += helloworld.cpp

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

2. 通过编译出来的qt5 对demo 进行测试:

在qt源码目录下执行:

arm-qt/bin/qmake -project
arm-qt/bin/qmake
arm-qt/bin/qmake helloworld.cpp

将产生的二进制文件helloworld 下载到嵌入式开发板,给权限,执行./helloworld 即可。

chmod 777 helloworld
./helloworld

?******* 如果提示库文件出错,请将xxx5.12.9.so 库文件名均改成xxx5.so

文章来源:https://blog.csdn.net/Chhjnavy/article/details/135559056
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。