从cygwin64编译32位代码 [英] compile 32bit code from cygwin64

查看:199
本文介绍了从cygwin64编译32位代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用gcc开发工具在win7-64上安装了Cygwin64,我只是注意到它会产生64位二进制文​​件。 (好吧,这并不令人惊讶:o)是否有办法使其生成一些32位二进制文​​件?

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?

我正在为64位编译Windows的socat工具,工作正常,但我正在尝试使另一个版本适合XP-32。

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.

配置脚本不起作用似乎支持 -b 32 开关(我必须从此线程,如果我尝试在 CFLAGS -m32 开关c $ c>配置 失败:

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

是否可以同时安装Cygwin32,或者可以使用其他设置或其他cygwin软件包编译32位代码吗?

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

编辑:
我发现我的cygwin64 / gcc无法编译一个简单的32位 hello.c 程序:

#include <stdio.h>

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

带有 gcc -o hello.exe hello。 c 可以正常工作,但是 gcc -o hello.exe hello.c -m32 吐口水

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


推荐答案

configure是autotools的一部分,与原始问题无关。您可以为其构建C程序的两个32位运行时环境。 CYGWIN-32和MINGW32。我不会详细介绍它们之间的差异,但是cygwin32程序与posix / Linux兼容(大多数情况下),因此我更喜欢这种环境。以下是有关如何在cygwin64安装上制作cygwin32应用程序的详细信息:

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 软件包和 cygwin64安装程序中的cygwin32-w32api-runtime 软件包(如果尚未执行此操作)。这将安装您需要测试程序的ac编译器i686-pc-cygwin-gcc和运行时cygwin1.dll(或者您可以在cygwin32安装中对其进行测试)。

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)假设将要编译上面的hello.c程序,请使用export CC从cygwin64 shell中选择C编译器和运行时,或者仅执行C编译器,因为默认的make输出显示在 make hello下方:

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),您会注意到什么都没有发生,因为Cygwin 32位运行时不在路径中。因此,将其添加到路径中,即可正确执行

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)坐下,喝一杯咖啡,然后欢喜

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

这篇关于从cygwin64编译32位代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆