一、Linux 系統編譯工具鏈實踐:mininim 源碼編譯
-
虛擬機 Ubuntu 編譯流程
-
環境配置問題
編譯時遇到虛擬機無法聯網的情況,通過連接個人熱點解決(校園網限制導致無法訪問外部資源)。
執行?./bootstrap
?時報錯?gnulib-tool: command not found
,因缺少 gnulib 工具和項目目錄結構不完整,通過?sudo apt install gnulib
?解決。
運行?./mininim
?時提示動態庫缺失,安裝?liballegro5.2
?和?liballegro-dev
?解決。 -
打包與遷移
打包步驟包括復制可執行文件、游戲資源及依賴庫,通過?ldd
?命令自動獲取依賴庫路徑,使用?cp -L
?確保復制實際文件而非鏈接。
啟動腳本?run_mininim.sh
?通過設置?LD_LIBRARY_PATH
?指向本地庫目錄,確保程序在目標機器獨立運行。
-
-
樹莓派編譯
? ? ? ? ? 換源配置
?將樹莓派軟件源替換為清華鏡像,適用于 Debian 12(bookworm)系統,提升下載速度。
配置:
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://security.debian.org/debian-security bookworm-security main contrib non-free
依賴管理
先通過?apt-get remove
?清除舊版 allegro5 庫,再用?apt-get build-dep
?自動檢測并安裝編譯依賴。
從 Gitee 下載 allegro5 v5.2.5 源碼,通過 CMake 配置編譯環境:
cd allegro5_v5.2.5/build
cmake ..
make
二、跨平臺開發:Android 交叉編譯與部署
環境準備
- 安裝 Android NDK R25b,通過?
adb shell getprop ro.product.cpu.abi
?查看手機架構(如 aarch64)。 - 配置交叉編譯工具鏈變量
編譯流程
- 克隆 mininim 源碼后,通過?
./bootstrap
?生成配置腳本,指定 Android 目標架構:
./configure --host=aarch64-linux-android \
CC="$CC" AR="$AR" \
LUA_LIB="-L$LUA50_INSTALL/lib -llua50 -llualib50"
make -j$(nproc)
``` {insert\_element\_9\_}
部署與調試
使用 adb push 傳輸文件到手機 /data/local/tmp 目錄,通過 chmod +x 賦予執行權限。
若程序無法運行,檢查依賴庫是否完整或架構是否匹配(如手機為 ARM64 但編譯為 ARM32)。
三、樹莓派 GPIO 編程:流水燈實驗
-
硬件連接
選用 BCM 編號 17、27、22、10、9、11 的 GPIO 引腳,搭配 GND 完成電路連接。? ? ? ? ?每個 GPIO 引腳通過電阻連接 LED 正極,負極接地,避免短路。 - 程序實現
import RPi.GPIO as GPIO
import timeLED_PINS = [17, 27, 22, 10, 9, 11]
DELAY = 0.3 # 秒級延時控制流水速度def setup():GPIO.setmode(GPIO.BCM)GPIO.setwarnings(False)for pin in LED_PINS:GPIO.setup(pin, GPIO.OUT)GPIO.output(pin, GPIO.LOW) # 初始化為低電平def flow_animation():try:while True:for pin in LED_PINS:GPIO.output(pin, GPIO.HIGH)time.sleep(DELAY)GPIO.output(pin, GPIO.LOW)except KeyboardInterrupt:GPIO.cleanup() # 釋放資源if __name__ == "__main__":setup()flow_animation()
運行與異常處理
執行 sudo python3 led_flow.py 啟動程序,通過 Ctrl+C 正常退出。
若提示引腳被占用,用 ps aux | grep led_flow.py 查看進程并終止。
四、技術總結與問題拓展
-
編譯工具鏈關鍵要點
- 跨平臺編譯需嚴格匹配目標架構(如樹莓派 ARM、Android aarch64),通過?
--host
?參數指定。 - 動態庫依賴管理是打包核心,
ldd
?+?cp -L
?可自動收集所有依賴文件。
- 跨平臺編譯需嚴格匹配目標架構(如樹莓派 ARM、Android aarch64),通過?
-
GPIO 編程注意事項
- 樹莓派 GPIO 引腳僅支持 3.3V 電平,避免直接連接 5V 設備以防燒毀。
- 程序結束時必須調用?
GPIO.cleanup()
,否則可能導致引腳狀態鎖定。
備份樹莓派專用源:
sudo gedit /etc/apt/sources.list
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free
non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib
nonfree
non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib
non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main
contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib
non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main
contrib non-free non-free-firmware
deb https://security.debian.org/debian-security bookworm-security main contrib
non-free non-free-firmware
deb-src https://security.debian.org/debian-security bookworm-security main
contrib non-free non-free-firmware
deb http://archive.debian.org/debian buster main contrib non-free
deb-src http://archive.debian.org/debian buster main contrib non-free
sudo apt-get update
生成配置:
?
./bootstrap
You may need to add #include directives for the following .h files.
#include <getopt.h>
#include <glob.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <wchar.h>
#include "argp.h"
#include "error.h"
#include "fnmatch.h"
#include "getpass.h"
#include "nonblocking.h"
#include "progname.h"
#include "vasnprintf.h"
#include "vasprintf.h"
#include "xprintf.h"
#include "xvasprintf.h"
You may need to use the following Makefile variables when linking.
Use them in <program>_LDADD when linking a program, or
in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library.
$(LTLIBINTL) when linking with libtool, $(LIBINTL) otherwise
$(LTLIBTHREAD) when linking with libtool, $(LIBTHREAD) otherwise
Don't forget to
- add "gnulib/Makefile" to AC_CONFIG_FILES in ./configure.ac,
- mention "gnulib" in SUBDIRS in Makefile.am,
- mention "-I gnulib/m4" in ACLOCAL_AMFLAGS in Makefile.am,
- invoke gl_EARLY in ./configure.ac, right after AC_PROG_CC,
- invoke gl_INIT in ./configure.ac.