Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compile 32bit code from cygwin64

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
like image 344
Seki Avatar asked May 08 '15 08:05

Seki


2 Answers

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

like image 62
Kurt Godwin Avatar answered Oct 20 '22 12:10

Kurt Godwin


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.

like image 27
David Macek Avatar answered Oct 20 '22 12:10

David Macek