【问题标题】:Can't build 32-bit binaries on a 64 bit system无法在 64 位系统上构建 32 位二进制文​​件
【发布时间】:2021-11-18 08:48:35
【问题描述】:

简介

虽然我能够为我的 64 位 Windows 系统构建二进制文件,但我无法找到生成 32 位二进制文​​件的方法,尽管我已经尝试了很多方法,但仍然出现大量错误. 具体我正在尝试的是在 wincon 文件夹下为 32 位系统构建 PDCurses-3.9(专用在我试图维护的这个unicurses 库中使用)

但是到目前为止我所尝试的只给了我错误

  • 主要是我所做的唯一重大更改是将-m32 标志添加到wincon/Makefile,如下所示:
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 专业版 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,但 我有点菜鸟,所以我没有成功 [...] 有什么想法吗?提前致谢

【问题讨论】:

    标签: windows gcc linker mingw pdcurses


    【解决方案1】:

    我不确定-m32 是否真的能够在 Windows 上切换目标。如果它有任何工作机会,您实际上需要一个针对 32 位 on your systemx86_64-w64-mingw32 的编译器,不是吗,您可能想要 i686-w64-mingw32 并且可能在您的 msys 文件夹中的 mingw32 中?

    如果构建脚本调用 gcc.exe 时没有任何类型的目标前缀,那么正确的编译器需要位于您的 %path% 的第一个位置。

    【讨论】:

    • 你是对的!,我还没有安装工具链,我很傻,我认为x86_64-w64-mingw32也出于某种原因与32兼容。实际上,我只需要打开MSYS2 MinGW 32-bit 并像pacman -S --needed base-devel mingw-w64-i686-toolchain 一样安装它,然后将C:\msys64\mingw32\bin 添加到%path%,由于这个确切原因,永久高于64 [...]。 非常感谢(:这让我困惑了好几个小时。
    猜你喜欢
    • 2011-09-08
    • 1970-01-01
    • 2014-04-22
    • 1970-01-01
    • 1970-01-01
    • 2011-01-24
    • 2020-07-06
    相关资源
    最近更新 更多