You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编译无terminfo的ncurses时遇_nc_fallback未定义错误的解决求助

问题

需要构建可在无terminfo的Android Shell中运行的静态应用,常规编译ncurses会出现“can't find terminfo”错误。使用以下configure参数编译后,执行make时触发“undefined reference to `_nc_fallback'”链接错误,寻求正确编译方案:

./configure --prefix=$TMUXTARGET --without-database --with-fallbacks=xterm-256color,vt100 --without-xterm-new --disable-home-terminfo --with-termlib --enable-termcap --disable-database

编译报错信息:

In [205]: !make V=1
cd man && make DESTDIR="" RPATH_LIST="/home/qgb/work/tmux-static/local/lib" all
make[1]: Entering directory '/home/qgb/work/tmux-static/ncurses-6.2/man'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/qgb/work/tmux-static/ncurses-6.2/man'
cd include && make DESTDIR="" RPATH_LIST="/home/qgb/work/tmux-static/local/lib" all
make[1]: Entering directory '/home/qgb/work/tmux-static/ncurses-6.2/include'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/qgb/work/tmux-static/ncurses-6.2/include'
cd ncurses && make DESTDIR="" RPATH_LIST="/home/qgb/work/tmux-static/local/lib" all
make[1]: Entering directory '/home/qgb/work/tmux-static/ncurses-6.2/ncurses'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/qgb/work/tmux-static/ncurses-6.2/ncurses'
cd progs && make DESTDIR="" RPATH_LIST="/home/qgb/work/tmux-static/local/lib" all
make[1]: Entering directory '/home/qgb/work/tmux-static/ncurses-6.2/progs'
gcc ../objects/infocmp.o ../objects/dump_entry.o -L../lib  -DHAVE_CONFIG_H -I../progs -I. -I../include -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -DNDEBUG -O2 --param max-inline-insns-single=1200 -L../lib  -lncurses -ltinfo    -o infocmp
../lib/libtinfo.a(lib_setup.o): In function `_nc_setupterm':
lib_setup.c:(.text+0x924): undefined reference to `_nc_fallback'
collect2: error: ld returned 1 exit status
Makefile:284: recipe for target 'infocmp' failed
make[1]: *** [infocmp] Error 1
make[1]: Leaving directory '/home/qgb/work/tmux-static/ncurses-6.2/progs'
Makefile:118: recipe for target 'all' failed
make: *** [all] Error 2
解决方案

_nc_fallback未定义的问题,是因为启用--with-termlib拆分出libtinfo后,fallback相关代码仅存在于libncurses中,链接时符号无法匹配导致的。按以下步骤调整配置即可解决:

  1. 清理编译残留
    先清除旧配置和编译文件,避免干扰:

    make distclean
    
  2. 调整configure参数
    使用以下参数配置,确保fallback代码被正确编译进静态库,适配Android环境:

    ./configure \
      --prefix=$TMUXTARGET \
      --host=arm-linux-androideabi \  # 根据目标架构调整:arm64用aarch64-linux-android
      --without-database \
      --with-fallbacks=xterm-256color,vt100 \
      --without-xterm-new \
      --disable-home-terminfo \
      --enable-static \
      --disable-shared \
      --enable-termcap \
      --without-termlib \  # 不拆分libtinfo,合并所有终端符号到libncurses
      --disable-db-install \
      --disable-stripping
    
    • --host必须指定对应Android交叉编译工具链的前缀,根据你的目标设备架构选择。
    • 移除--with-termlib,避免符号拆分导致的链接错误。
    • 明确开启静态编译、关闭动态库,满足Android静态应用的需求。
  3. 编译安装
    执行编译和安装命令:

    make -j$(nproc)
    make install
    
  4. 验证结果
    检查$TMUXTARGET/lib目录下是否生成libncurses.a静态库,后续编译你的应用时链接该库即可,无需依赖terminfo数据库。

内容的提问来源于stack exchange,提问作者CS QGB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 03:28:27