windowsgcclinkermingwpdcurses

Can't build 32-bit binaries on a 64 bit system


Intro

While I'm able to build the binaries for my 64-bit windows system, i'm unable to find a way to produce the 32-bit ones, although i've tried many things I still get a banch of errors. Specifically what I'm trying, is to build PDCurses-3.9 under the wincon folder for 32-bit Systems (dedicated for use in this unicurses library that i'm trying to maintain).

But what I've tried so far gave me only Errors

ifeq ($(DEBUG),Y)
    CFLAGS  = -g -Wall -DPDCDEBUG
    LDFLAGS = -g
else
    CFLAGS  = -m32 -O2 -Wall # <-- 
    LDFLAGS = -m32           # <--
endif
...
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

^ ... = many of those

System Infos

Windows 10 Pro 64-bit | 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

Outro

Generally i've experimented with changing the makefile but I'm a bit noob when it comes to those stuff and so I was unsuccessful [...] any Idea? Thanks in advance


Solution

  • I'm not sure if -m32 is actually able to switch targets on Windows. If it is going to have any chance of working you actually need to have a compiler that targets 32-bit on your system and x86_64-w64-mingw32 is not it, you probably want i686-w64-mingw32 and that might be in mingw32 in your msys folder?

    If the build script is invoking gcc.exe without any kind of target prefix then the correct compiler needs to be first in your %path%.