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

64位Windows系统下编译32位PDCurses-3.9二进制报错求助

简介

我可以在64位Windows系统上正常构建二进制文件,但找不到生成32位二进制的方法,尝试多种操作后仍出现大量报错。具体需求为编译wincon目录下的PDCurses-3.9的32位版本,用于我正在维护的unicurses库。

已尝试操作及报错信息

  • 我目前仅对*wincon/Makefile*做了一处核心修改,即添加-m32编译参数,修改内容如下:
ifeq ($(DEBUG),Y)
    CFLAGS  = -g -Wall -DPDCDEBUG
    LDFLAGS = -g
else
    CFLAGS  = -m32 -O2 -Wall # <-- 
    LDFLAGS = -m32           # <--
endif
  • 执行make -f Makefile DLL=Y命令编译时,得到如下报错:
...
windres -i ../common/pdcurses.rc pdcurses.o
gcc -Wl,--out-implib,pdcurses.a -shared -o pdcurses.dll addch.o addchstr.o addstr.o attr.o beep.o bkgd.o border.o clear.o color.o delch.o deleteln.o getch.o getstr.o getyx.o inch.o inchstr.o initscr.o inopts.o insch.o insstr.o instr.o kernel.o keyname.o mouse.o move.o outopts.o overlay.o pad.o panel.o printw.o refresh.o scanw.o scr_dump.o scroll.o slk.o termattr.o touch.o util.o window.o debug.o pdcclip.o pdcdisp.o pdcgetsc.o pdckbd.o pdcscrn.o pdcsetsc.o pdcutil.o pdcurses.o
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot export COLORS: symbol not found
    ... 
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: i386 architecture of input file `addch.o' is incompatible with i386:x86-64 output
    ...
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: color.o:color.c:(.text+0x670): undefined reference to `_getenv'
    ... 
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: pdcutil.o:pdcutil.c:(.text+0x4a): undefined reference to `__imp__GetTickCount@0'
collect2.exe: error: ld returned 1 exit status
make: *** [pdcurses.dll] Error 1

^ ... 代指大量同类报错

系统信息

Windows 10 Pro 64位 | Intel(R) Core(TM) i7-6700 CPU

> gcc --version
gcc (Rev5, Built by MSYS2 project) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-pc-mingw32

补充说明

我也尝试过调整Makefile的其他配置,但我对这类编译操作经验不足,均未解决问题,恳请各位提供可行解决方案,多谢!


解决方案

报错的核心原因是当前使用的64位MinGW工具链仅添加-m32参数无法完成全流程32位编译,存在资源编译架构不匹配、DEBUG分支参数缺失、缺少32位依赖库三类问题,按以下步骤操作即可解决:

  1. 安装32位MinGW工具链
    打开MSYS2自带的MSYS终端,执行以下命令安装32位编译依赖:
pacman -S mingw-w64-i686-gcc mingw-w64-i686-winpthreads

安装完成后,从Windows开始菜单找到「MSYS2 - MinGW 32-bit」终端启动,不要使用之前的MinGW 64位终端。
2. 修改Makefile完整配置
需要同步给DEBUG分支添加-m32参数,同时指定资源编译器生成32位资源文件,修改后的配置片段如下:

ifeq ($(DEBUG),Y)
    CFLAGS  = -m32 -g -Wall -DPDCDEBUG
    LDFLAGS = -m32 -g
    WINDRES = windres -F pe-i386
else
    CFLAGS  = -m32 -O2 -Wall
    LDFLAGS = -m32
    WINDRES = windres -F pe-i386
endif

再找到Makefile中调用windres的行,将原来的硬编码调用改为使用变量:

# 原写法
# windres -i ../common/pdcurses.rc pdcurses.o
# 替换为
$(WINDRES) -i ../common/pdcurses.rc pdcurses.o
  1. 清理残留编译文件
    删除之前编译生成的所有.o、.dll、.a后缀的中间文件,也可以执行make clean -f Makefile清理。
  2. 重新编译
    在32位MinGW终端中执行make -f Makefile DLL=Y即可正常生成32位PDCurses库。
    编译完成后可执行file pdcurses.dll验证,输出包含PE32 executable即为编译成功。

内容的提问来源于stack exchange,提问作者Giorgos Xou

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 01:57:02