对于qlibc的交叉编译。该文章的目标是编译一套aarch64 Linux Debian嵌入式版本上可以运行的版本库,接下来就开始趟坑。老套路,先把linux桌面版搞好,然后 移植到嵌入式Linux Debian 板子上
对于qlibc的交叉编译。该文章的目标是编译一套aarch64 Linux Debian嵌入式版本上可以运行的版本库,接下来就开始趟坑。老套路,先把linux桌面版搞好,然后 移植到嵌入式Linux Debian 板子上。
1 qlibc简介
qLibc 这个项目就是提供一个通用的 C/C++ 库,包括所有种类的容器和常用工具函数。这里详细介绍下,主要分为两大部分:
核心API:
- Containers for Key/Value pairs
- Tree Table --- in binary tree(left-leaning red-black tree) data structure.
- Hash Table --- in hash-based data structure.
- Static Hash Table --- in fixed size memory(array/mmapped/shared).
- List Table --- in (doubly) linked-list data structure.
- Containers for Objects
- List --- Doubly Linked List.
- Vector --- implements a growable array of elements.
- Queue --- FIFO(First In First Out) implementation.
- Stack --- LIFO(Last In First Out) implementation.
- General utilities.
- String --- string trimmer, modifier, replacer, case converter, pattern detectors, ...
- I/O --- non-blocking I/O, stream reader/writer, ...
- File --- file locking, file/directory hander, path correctors, ...
- IPC, Semaphore Shared-memory
- En/decoders --- Url en/decoder, Base64 en/decoder, Hex en/decoder, ...
- Hashes --- Murmur hases, FNV hases, MD5 hashes, ...
- Time --- time diff, time format converstion, ...
扩展API:
- Apache-style Configuration File Parser.
- INI-style Configuration File Parser.
- HTTP client.
- Rotating File Logger.
- Database(MySQL) interface.
- Token-Bucket
可以说qlibc的核心目的就是用于提供qlibc的基础API。
qlibc项目地址:GitHub qLibc Project
2 Linux 本地编译 & 交叉编译
2.1 Linux(ubuntu20.04)上qlibc的编译
qlibc通过configure文件来配置,流程如下:
$./configure
$make
$sudo make install
这里关于安装位置,可以通过--prefix=具体路径来设置。编译后生成库文件内容为:
├── libqlibc.a
├── libqlibcext.a
├── libqlibcext.so -> libqlibcext.so.2
├── libqlibcext.so.2
├── libqlibc.so -> libqlibc.so.2
└── libqlibc.so.2
2.2 aarch64交叉编译与移植
因为是用aarch64交叉编译,需要提前配置环境,安装如下软件:
sudo apt install binutils-aarch64-linux-gnu-dbg binutils-aarch64-linux-gnu cpp-aarch64-linux-gnu \
g++-10-aarch64-linux-gnu g++-9-aarch64-linux-gnu g++-aarch64-linux-gnu g++ \
gcc-10-aarch64-linux-gnu-base gcc-9-aarch64-linux-gnu-base gcc-aarch64-linux-gnu \
pkg-config-aarch64-linux-gnu qemu-efi-aarch64 gcc arch-test
在qlibc的目录中创建一个类似configure的配置文件aarch64-configure,内容为:
#!/bin/bash
ARCH="aarch64"
DEST_CPU="arm64"
HOST_OS="linux"
HOST_ARCH="x86_64"
export LINK_host="g++"
export CXX_host="g++"
export CC_host="gcc"
export AR_host="ar"
export CC=aarch64-linux-gnu-gcc
export CXX=aarch64-linux-gnu-g++
export LD=aarch64-linux-gnu-ld
export RANLIB=aarch64-linux-gnu-ranlib
export AR=aarch64-linux-gnu-ar
export AS=aarch64-linux-gnu-as
if [ -f "configure" ]; then
./configure --prefix=$PWD/out_aarch64_qlibc \
--host=aarch64-linux-gnueabi \
fi
配置后接下来和桌面版linux类似:
$./aarch64-configure
$make
$sudo make install
这里执行后安装位置默认为:out_aarch64_qlibc。同样可以通过--prefix=具体路径来自定义设置。