»
(008)CubeIDE实现USB外设*
(013)OpenWrt交叉编译
(018)C99 的指针*
(019)C99 只有值赋值,没有move*
(022)POSIX线程库pthread的同步锁*
(023)POSIX线程库pthread的多线程*
(027)C99标准库中的计时与等待 *
(028)C语言中的高精度计算库GMP *
(029)C语言中的Web服务*
(030)C语言中的字符转码ICU*
(031)从几个方面显然C语言比C++效率高*
一个概念:交叉编译、cross-compilation,英文原意:跨平台编译。
也就是在x86_64架构的操作系统上编译arm32架构的操作系统上运行的程序或者在x86_64架构的操作系统上编译arm64架构的操作系统上运行的程序。
下面是x86_64架构下的OpenWrt交叉编译过程:
1. 在OpenWrt官网下载对应的toolchain工具包,并解压缩到/home/xxx/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/目录
2.后续使用root账号操作
sudo su
[输入root账号密码]
3.在终端中运行以下命令设置环境变量的:
PATH=$PATH:/home/xxx/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl/bin
export PATH
STAGING_DIR=/home/xxx/toolchain-aarch64_cortex-a72_gcc-12.3.0_musl
export STAGING_DIR
4.下载OpenWrt源码:
git clone https://git.openwrt.org/openwrt/openwrt.git
git checkout v23.05.5
5.安装需要的软件包
cd openwrt
./scripts/feeds update -a
cd ../
mkdir host
mkdir build
./scripts/feeds install -a
6.开始openwrt的编译配置(进入视频上的熟悉界面-编译配置界面)
make menuconfig
界面如下
.config - OpenWrt Configuration
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────── OpenWrt Configuration ──────────────────────────────────────────────────────┐
│ Arrow keys navigate the menu. <Enter> selects submenus ---> (or empty submenus ----). Highlighted letters are hotkeys. │
│ Pressing <Y> includes, <N> excludes, <M> modularizes features. Press <Esc><Esc> to exit, <?> for Help, </> for Search. │
│ Legend: [*] built-in [ ] excluded <M> module < > module capable │
│ │
│ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │
│ │ Target System (Atheros ATH79) ---> │ │
│ │ Subtarget (Generic) ---> │ │
│ │ Target Profile (8devices Carambola2) ---> │ │
│ │ Target Images ---> │ │
│ │ [ ] Enable experimental features by default (NEW) │ │
│ │ Global build settings ---> │ │
│ │ [ ] Advanced configuration options (for developers) (NEW) ---- │ │
│ │ [ ] Build the OpenWrt Image Builder (NEW) │ │
│ │ [ ] Build the OpenWrt SDK (NEW) │ │
│ │ [ ] Package the OpenWrt-based Toolchain (NEW) │ │
│ └────────────────────────────v(+)──────────────────────────────────────────────────────────────────────────────────────────────┘ │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ <Select> < Exit > < Help > < Save > < Load > │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
7.配置过程中指定目标硬件主板以及其他配置项后Save、Exit
8.Exit后,开始编译
FORCE_UNSAFE_CONFIGURE=1
export FORCE_UNSAFE_CONFIGURE
make -j4 V=s
9.make后,系统会生成您勾选的镜像文件
10.用烧写工具烧写到SD卡,将SD卡插入树莓派4B主板,即可让树莓派4B变成OpenWrt路由器。
musl/gdb-12.1/gdb/data-directory/python': No such file or directory的问题的解决:
ln -s -f /usr/local/bin/python3 /usr/local/bin/python
附注:
什么是eabi?为什么要使用交叉编译?
eabi就是Embeded Application Binary Interface,也就是嵌入式应用程序二进制接口。和STM32一样,OpenWrt用的也是eabi,那个toolchain的gcc也就是arm版的交叉编译eabi。使用eabi和交叉编译,是因为,stm32的简单芯片不具备编译环境或者芯片上的编译环境的速度比不上PC机上的编译速度,比如:arm64的树莓派4B性能没有x86_64的PC机性能高。