提示:curses 是一个用于创建 文本界面(TUI, Text User Interface) 的 Python 标准库(基于 Unix 系统的 ncurses 库封装),核心作用是让开发者脱离传统命令行的 “一行一行输出” 限制,实现类似图形界面的交互效果 —— 比如窗口分割、光标控制、颜色显示、键盘快捷键响应等,无需依赖 GUI 环境(如 GTK、Qt),仅需终端支持。
【Linux】【harmonyOs】【Curses】交叉编译鸿蒙系统的 Curses 库
前言
例如:使用到Curses 库,或者其他库依赖Curses库时,需要先交叉编译一下Curses。
– Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:85 (MESSAGE): Curses library not
found. Please install appropriate package,remove CMakeCache.txt and rerun cmake. Call Stack (most recent call first): cmake/readline.cmake:128 (FIND_CURSES)cmake/readline.cmake:202 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:427 (MYSQL_CHECK_EDITLINE)– Configuring incomplete, errors occurred!
curses 库与底层的 ncurses 库是 “封装与被封装” 的核心关系 ——curses 是 Python 对 Unix 系统原生
ncurses 库的 高层封装,本质是通过 Python 接口调用 ncurses 的底层功能,同时简化了开发流程(如自动处理终端初始化 /
清理)
一、下载代码
wget https://invisible-mirror.net/archives/ncurses/ncurses-6.4.tar.gz # 下载代码
tar -xzvf ncurses-6.4.tar.gz # 解压
mkdir -p usrinstall/ncurses # 新建安装目录

二、编译代码
1. 查看目录结构
cd ncurses-6.4/
ls
说明此库使用 configure 进行编译
2. 执行 configure 编译命令
–prefix 后面的路径改成你自己新建的安装目录
./configure
--prefix=/home/an/workspace/usrinstall/ncurses
--host=aarch64-linux-ohos
--target=aarch64-linux-ohos
--without-tests
--without-progs
--enable-shared=yes
--with-shared
--with-pic
--enable-static
--enable-widec
--disable-rpath
--with-build-cc=$(which gcc)
CFLAGS="-fPIC -Qunused-arguments -Wno-error=implicit-function-declaration --sysroot=/home/an/ohos_tools/ohos-sdk/linux/native/sysroot -march=armv8-a"
LDFLAGS="--target=aarch64-linux-ohos --sysroot=/home/an/ohos_tools/ohos-sdk/linux/native/sysroot -L/home/an/ohos_tools/ohos-sdk/linux/native/sysroot/usr/lib -lc -Wl,-soname,libncursesw.so.6"
32位
./configure
--prefix=/home/an/workspace/usrinstall/ncurses
--host=arm-linux-ohos
--target=arm-linux-ohos
--without-tests
--without-progs
--enable-shared=yes
--with-shared
--with-pic
--enable-static=yes
--enable-widec=yes
--disable-rpath
--disable-werror
--silent
CFLAGS="-mfloat-abi=softfp -mthumb -O2 -ffunction-sections -fdata-sections"
CXXFLAGS="-mfloat-abi=softfp -mthumb -O2 -ffunction-sections -fdata-sections"
LDFLAGS="-mfloat-abi=softfp -ldl -lpthread -Wl,--gc-sections"
开始报错 (不认识ohos)
Configuring NCURSES 6.4 ABI 6 (Thu Nov 13 03:09:03 UTC 2025) checking
for package version… 6.4 checking for package patch date… 20221231
checking build system type… x86_64-pc-linux-gnu checking host system
type… Invalid configurationohos’ not
aarch64-linux-ohos': OS
recognized configure: error: /bin/sh ./config.sub aarch64-linux-ohos
failed
解决方法: 手动下载支持的配置
cd /home/an/workspace/ncurses-6.4
# 备份旧版本脚本(避免覆盖后无法恢复)
mv config.sub config.sub.old
mv config.guess config.guess.old
# 下载支持 OHOS 的新版本脚本(来自 GNU 最新仓库,已收录 OHOS)
wget -O config.sub https://git.savannah.gnu.org/cgit/config.git/plain/config.sub
wget -O config.guess https://git.savannah.gnu.org/cgit/config.git/plain/config.guess
# 加执行权限(否则脚本无法运行)
chmod a+x config.sub config.guess
下载完成如下

2. 重新执行 configure 执行成功

3. 再执行make,make install 安装
make
make install

4. 安装目录出现上图产物,说明编译成功,在使用file命令验证是ARM64。

总结
提示:这里对文章进行总结:
例如:成功进行了一个C库的交叉编译。


