| 項目 | 版本/路徑 |
| 宿主機 | Linux 2.6.18 |
| 交叉編譯工具鏈 | /usr/local/arm/2.95.3/bin/arm-linux- |
| 工作目錄 | /home/mad/ |
| 安裝前綴 | /home/mad/lib |
| 原始碼套件 | zlib-1.1.4、libid3tag-0.15.1b、libmad-0.15.1b、madplay-0.15.2b |
編譯順序與關鍵參數
原則:依賴關係由底層向上(zlib → libid3tag → libmad → madplay),全部靜態連結(--disable-shared),避免執行時缺庫。
1. zlib(需修改 configure 指定交叉工具)
cd zlib-1.1.4
# 修改 configure 第 24、25、63 行:
# AR="${AR-/usr/local/arm/2.95.3/bin/arm-linux-ar rcs}"
# RANLIB="${RANLIB-/usr/local/arm/2.95.3/bin/arm-linux-ranlib}"
# cc=${CC-/usr/local/arm/2.95.3/bin/arm-linux-gcc}
./configure --prefix=/home/mad/lib
make && make install
2. libid3tag(依賴 zlib)
cd libid3tag-0.15.1b
./configure --host=arm-linux --prefix=/home/mad/lib --disable-shared \
CPPFLAGS=-I/home/mad/lib/include LDFLAGS=-L/home/mad/lib/lib
make && make install
3. libmad(核心解碼庫)
cd libmad-0.15.1b
./configure --host=arm-linux --prefix=/home/mad/lib --disable-shared
make && make install
4. madplay(播放器前端)
cd madplay-0.15.2b
./configure --host=arm-linux --prefix=/home/mad/lib --disable-shared --enable-static \
CPPFLAGS=-I/home/mad/lib/include LDFLAGS=-L/home/mad/lib/lib
make
# 產生 madplay 執行檔,無需 make install
部署與測試
- 將編譯產生的
madplay 執行檔複製到開發板(如透過 NFS、TFTP 或 SD 卡)。
- 開發板上執行:
./madplay Nobody.mp3,應可聽到音樂。
重要提醒:音訊裝置節點
Madplay 預設使用 /dev/dsp。若開發板有多個音訊裝置(如 /dev/dsp1),需修改 madplay/audio_oss.c 第 78 行的裝置路徑重新編譯。
常見問題排查
- 編譯報「找不到 zlib.h」:確認
CPPFLAGS 指向 /home/mad/lib/include。
- 連結報「undefined reference to `inflate`」:確認
LDFLAGS 指向 /home/mad/lib/lib 且 zlib 已先安裝。
- 執行報「Can't open /dev/dsp」:核心未啟用 OSS 相容層,或裝置節點名稱不同,請修改
audio_oss.c。
- 靜態連結體積過大:可在
configure 加入 --enable-static --disable-shared 並配合 strip madplay 減小體積。
相關連結
- 上一篇文章: 【編程好習慣】goto 語句的正當防衛:錯誤處理與資源釋放的最佳拍檔
- 下一篇文章: 【編程好習慣】資源釋放鐵律:嚴格遵循「分配逆序」原則
Copyright ©
程式碼之家 All Rights Reserved