泰晓科技 -- 聚焦 Linux - 追本溯源,见微知著!
网站地址:http://tinylab.org

随身Linux Lab实验盘:128G可当256G使
请稍侯

Linux Lab 真板开发日志(4):上手全平台 GUI 库 GuiLite

贾献华 创作于 2021/02/22

By 贾献华 of TinyLab.org Jan 30, 2021

前言

本文所采用的 i.MX6ULL Pro 开发板可以直接从 泰晓科技自营店 选购。

GuiLite 简介

GuiLite 是一个跨平台、轻量级、仅需包含头文件即可使用的图形库:

GuiLite

首先直接在真板测试

下载编译工具、源码并编译:

$ sudo apt update -y
$ sudo apt install git make cmake gcc g++ -y
$ git clone https://gitee.com/idea4good/GuiLite
$ cd GuiLite/workspace
$ cmake -D CMAKE_C_COMPILER="/usr/bin/arm-linux-gnueabihf-gcc" -D CMAKE_CXX_COMPILER="/usr/bin/arm-linux-gnueabihf-g++" .

报错:

debian@npi:~/code/GuiLite/workspace$ cmake -D CMAKE_C_COMPILER="/usr/bin/arm-linux-gnueabihf-gcc" -D CMAKE_CXX_COMPILER="/usr/bin/arm-linux-gnueabihf-g++" .
-- The CXX compiler identification is GNU 8.3.0
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabihf-g++
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabihf-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   236  100   236    0     0    343      0 --:--:-- --:--:-- --:--:--   343
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/debian/code/GuiLite/workspace

缺少 cacert.pem,我们再试试 Linux Lab。

转到 Linux Lab 运行 GuiLite

安装交叉编译工具等:

$ sudo apt update -y
$ sudo apt install g++-arm-linux-gnueabi gcc-arm-linux-gnueabi -y
$ sudo apt install cmake curl -y

下载源码并编译:

$ mkdir -p src/gui/
$ cd src/gui/
$ git clone https://gitee.com/idea4good/GuiLite
$ cd GuiLite/workspace/
$ cmake -D CMAKE_C_COMPILER="/usr/bin/arm-linux-gnueabi-gcc" -D CMAKE_CXX_COMPILER="/usr/bin/arm-linux-gnueabi-g++" .
$ make

复制到真板:

$ export BOARD_IP=192.168.1.138
$ scp libGuiLite.a root@$BOARD_IP:/usr/lib/

code

运行示例 GuiLiteSamples

这里用 HelloFont 作为演示,其它几个 Samples 操作大同小异,有一些仅部分开发板支持。

比如,我们的 imx6ull 是不支持 Hello3D 这个示例的。

同样下载源码并编译:

$ cd src/gui
$ git clone https://gitee.com/idea4good/GuiLiteSamples.git
$ cd GuiLiteSamples
$ sudo apt-get install g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf -y
$ cd HelloFont
$ cmake -D CMAKE_C_COMPILER="/usr/bin/arm-linux-gnueabi-gcc" -D CMAKE_CXX_COMPILER="/usr/bin/arm-linux-gnueabi-g++" .
$ make

接着复制到真板:

$ scp BuildLinux/HelloFont debian@$BOARD_IP:~/
$ cd /labs/linux-lab/
$ make login

hellofont

真板运行效果:

$ sudo ./HelloFont /dev/fb0
# sudo: unable to execute ./HelloFont: No such file or directory

查看文件类型,发现真板没有 /lib/ld-linux.so.3 文件,建立一个链接。


$ file HelloFont
HelloFont: ELF 32-bit LSB executable, ARM, EABI5 version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux.so.3, BuildID[sha1]=8dd36b554b3372787c920df5aa63b93f5daf7af3, for GNU/Linux 3.2.0, not stripped

$ sudo ln -sv /lib/ld-linux-armhf.so.3 /lib/ld-linux.so.3
'/lib/ld-linux.so.3' -> '/lib/ld-linux-armhf.so.3'

$ sudo ./HelloFont /dev/fb0

error.png

可以显示图片,但还是报错。

chmod: cannot access '.sync_build.sh': No such file or directory

回到原始代码,把 .sync_build.sh 复制到真板。

$ scp HelloFont/.sync_build.sh debian@$BOARD_IP:~

在真板运行还是报错,这次是 curl 有问题,和第一次在真板尝试一样,这次要解决这个问题。

curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

下载 cacert.pem ,并配置 CURL_CA_BUNDLE 之后即可正常运行。

$ wget -c https://curl.haxx.se/ca/cacert.pem
$ sudo cp cacert.pem /etc/ssl/certs/
$ export CURL_CA_BUNDLE=/etc/ssl/certs/cacert.pem
$ ./HelloFont /dev/fb0

HelloFont 命令

  • 输入 bb 开始动画
  • 输入 ss 截图,会在当前目录生成 snap_short.bmp 的图片
  • 输入 exit 退出程序

以下是其它几个示例的运行效果。

小结

小伙伴们可以参照示例自己动手写出简洁美观的界面,快动手试试吧!



Read Related:

Read Latest: