问题描述
我使用 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?
我正在为 windows 编译 socat 工具,以 64 位编译它可以工作,但我正在尝试制作另一个适用于 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.
configure
脚本似乎不支持 -b 32
开关(我必须从 这个线程,如果我尝试在 CFLAGS
中指定 -m32
开关> 对于 configure
它失败了:
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
程序:
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!
");
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 的一部分,与原始问题无关.您可以为两个 32 位运行时环境构建 C 程序.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) 在 cygwin64 安装程序中安装 cygwin32-gcc 包和 cygwin32-w32api-runtime 包,如果你还没有这样做的话.这将安装一个 c 编译器 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) 您会注意到实际上什么也没发生,因为 32 位的 Cygwin 运行时不在路径中.所以把它添加到路径中,它就会正确执行
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 位代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!