9

I installed Cygwin64 on a win7-64 with gcc dev tools and I just noticed that it produces 64bit binaries. (Well, not that surprising :o) Is there a mean to make it producing some 32bit binaries?

I am compiling the socat tool for windows, compiled in 64bit it is working, but I am trying to make another version suitable for an XP-32.

The configure script does not seem to support a -b 32 switch (that I must have seen for ming64 from this thread, and if I try to specify the -m32 switch in CFLAGS for configure it fails:

$ CFLAGS=-m32 ./configure
checking which defines needed for makedepend...
checking for a BSD-compatible install... /usr/bin/install -c
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/cygdrive/c/dev/tools/nettools/socat/socat-2.0.0-b8':
configure: error: C compiler cannot create executables
See `config.log' for more details

Would the option be to also install Cygwin32, or can I compile 32bit code with another setting or additional cygwin package?

Edit: I have found that my cygwin64/gcc cannot compile a simple hello.c program in 32bits:

#include <stdio.h>

int main (int argc, char *argv[]){
    printf("Hello, world!\n");
    return 0;
}

with a gcc -o hello.exe hello.c it works flawlessly, but gcc -o hello.exe hello.c -m32 spits

/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2//libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2//libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2//libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2//libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2//libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../libcygwin.a when searching for -lcygwin
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../libcygwin.a when searching for -lcygwin
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../libcygwin.a when searching for -lcygwin
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lcygwin
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -ladvapi32
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lshell32
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -luser32
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lkernel32
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2//libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2//libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2//libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2//libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2//libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc
collect2: error: ld returned 1 exit status
Seki
  • 11,135
  • 7
  • 46
  • 70
  • 1
    You could also check https://stackoverflow.com/questions/54206577/can-you-run-a-32-bit-cygwin-application-in-a-64-bit-installation/54216105#54216105 – CristiFati Jan 20 '19 at 01:32

4 Answers4

7

configure is part of autotools, and not relevant to the original question. There are two 32 bit runtime environments you can build a C program for. CYGWIN-32 and MINGW32. I will not go into details on the differences, but a cygwin32 program is posix/Linux compatible (mostly), so I prefer that environment. Here are the details on how to make a cygwin32 application on a cygwin64 install:

1)install cygwin32-gcc package and the cygwin32-w32api-runtime package in cygwin64 setup, if you have not already done this. this will install a c compiler i686-pc-cygwin-gcc and the runtime cygwin1.dll that you will need to test your program (or you can test it in a cygwin32 install).

2) assuming your hello.c program above is to be compiled, select the C compiler and runtime, from the cygwin64 shell by using export CC, or just execute the C compiler as the default make output shows below "make hello":

$ export CC=i686-pc-cygwin-gcc
$ make hello
i686-pc-cygwin-gcc     hello.c   -o hello
$ ./hello
$ *There is no output, program didn't work*

3) you will note that nothing really happens because Cygwin runtime for 32 bit is not in the path. So add it to the path, and it will execute correctly

$ export PATH=/usr/i686-pc-cygwin/sys-root/usr/bin:$PATH
$ ./hello
Hello, world!

$

4) Sit back, have a sip of coffee, and rejoice

Kurt Godwin
  • 71
  • 1
  • 2
  • Kurt, is there a way to build 32-bit app using `clang` compiler instead of `gcc`? I don't see `cygwin32-clang` nor `cygwin32-llvm` when I run the Cygwin64 setup. – Danijel Jul 24 '20 at 15:15
  • looks like you need to use mingw64-686-clang for llvm. does not look like there is support for llvm in CYGWIN32 right now. – Kurt Godwin Jul 29 '20 at 12:16
3

Cygwin provides packages containing cygwin-to-cygwin cross toolchains. There are cygwin32-* packages for building 32-bit from 64-bit Cygwin and cygwin64-* packages for building 64-bit from 32-bit Cygwin.

I've never used them, but I assume they work pretty much as any cross toolchain, so you should pass correct --host and --build arguments to your ./configure step.

David Macek
  • 868
  • 4
  • 10
  • I have the cygwin32-* packages installed and cross-compiling still refuses to work. I suspect there's a bug with the deployment of the toolchain... – Powerslave Jul 21 '15 at 10:06
  • @Powerslave, what's your `./configure` line? – David Macek Jul 21 '15 at 14:42
  • @Powerslave, what do you mean exactly? – jacerate Apr 08 '16 at 14:51
  • 1
    @jacerate You just invoke `i686-w64-mingw32-*.exe` (where `*` would be, e.g. `gcc`) directly, and it will happily compile to Win32 in a Cygwin64 environment. A prerequisite, of course, is having the `cygwin32-*` packages installed. – Powerslave Apr 10 '16 at 19:15
  • i686-pc-cygwin-gcc.exe (Cygwin32), i686-w64-mingw32-gcc.exe (Mingw32). – dns Jan 02 '21 at 00:56
3

Adding -m32 to the compiler does not make it select the correct libraries. You should check you have the i686-pc-cygwin-gcc compiler installed. To use that compiler you have to do something like this:

./configure --target=i686-pc-cygwin

Hope it helps :-)

millibit
  • 175
  • 1
  • 7
  • This answer is incomplete. Where do you run ./configure from? From the shell, I get this: -bash: ./configure: No such file or directory – Jay Elston Sep 20 '18 at 16:13
  • 2
    The configure script usually comes with the source you attempt to compile. The question asked specifically address the configure script. How to unpack the source code and locating the configure script is outside the scope of this question, IMHO. – millibit Oct 02 '18 at 19:33
  • This is right but you also need to specify `--build=i686-pc-cygwin`, or the `configure` script will guess wrong. – Noldorin Jan 22 '23 at 15:19
3

Update December 2022

All other solutions in this thread no longer work !!!

Apparently, Cygwin no longer has packages to install 32-Bit compiler and required libraries!

Legacy "Cygwin32" (setup-x86.exe) can only be installed by passing the following option to the setup program, otherwise the installer terminates immediately with obscure error message:

--allow-unsupported-windows

Also, because the 32-Bit installation packages no longer are available on the "official" mirrors, we must manually use the Cygwin Time Machine mirror at:

http://ctm.crouchingtigerhiddenfruitbat.org/pub/cygwin/circa/2022/11/23/063457 

This way we get a working 32-Bit gcc with all required libraries

Note: Cygwin32 can be installed side-by-side with Cygwin64 (in a separate dir) without problem.

xepak62241
  • 31
  • 3