cygwin下使用GCC生成的可执行文件 [英] Executable file generated using GCC under cygwin

查看:30
本文介绍了cygwin下使用GCC生成的可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Cygwin 并且将 GCC(版本 4.3.4 20090804 (release) 1)安装为 Cygwin 包.

I am using Cygwin and have GCC (version 4.3.4 20090804 (release) 1 ) installed as Cygwin package.

当我在 Cygwin shell 下使用 GCC 构建 C 代码时,生成的可执行输出文件是类型为 (PE32 可执行文件 for MS Windows (console) Intel 80386 32-bit) 并且只能在 Cygwin shell 下执行/运行,而不是 Windows shell/命令提示符上的独立 .exe.如果我尝试在 Windows 命令提示符下独立运行它,它会显示一个错误窗口,提示程序无法运行,因为您的计算机缺少 cygwin.dll".

When I built C code using GCC under Cygwin shell, the generated executable output file is a executable of type (PE32 executable for MS Windows (console) Intel 80386 32-bit) and it can only be executed/run under Cygwin shell, not as standalone .exe on Windows shell/command prompt. If I try to run it standalone on Windows command prompt it gives an error window saying "The program can't run because cygwin.dll is missing from your computer".

  1. 如何使这个 .exe 独立,它可以在任何其他系统的命令提示符下甚至在我自己的系统中执行?

  1. How can one make this .exe standalone, which can be executed on a command prompt of any other system or even in my own system?

我认为 Cygwin 下的 GCC 会构建一个 Linux 可执行文件(ELF 32 位 LSB 可执行文件),但事实并非如此.如何使用 gcc-cygwin 组合生成 *.out 类型的 Linux 可执行文件?

I thought GCC under Cygwin would build a Linux executable (ELF 32-bit LSB executable), but it's not so. How can I use the gcc-cygwin combination to generate a *.out kind of Linux executable file?

此外,我无法运行在 Linux-gcc 组合上生成的 Linux 可执行文件以在 Cygwin 下执行.

Also, I cannot run a Linux executable generated on a Linux-gcc combination to execute under Cygwin.

任何指针都会有所帮助.

Any pointers would be helpful.

推荐答案

尽管有广泛的谣言,Cygwin 不是 Linux 模拟器,即它不生成或运行 Linux 可执行文件.为此,您需要一台虚拟机或 coLinux.

Despite widespread rumours, Cygwin is not a Linux emulator, i.e. it doesn't produce or run Linux executables. For that you'll need a virtual machine or coLinux.

相反,Cygwin 是一个兼容层,旨在尽可能多地在 Windows 中实现 POSIX 和 Linux API.这意味着必须专门为 Cygwin 编译程序,但这也意味着它可以更好地与 Windows 集成,例如它允许您在同一个程序中混合使用 POSIX 和 Windows API.

Instead, Cygwin is a compatibility layer, which aims to implement as much as possible of the POSIX and Linux APIs within Windows. This means that programs have to be compiled specifically for Cygwin, but it also means that it's better integrated with Windows, e.g. it lets you mix POSIX and Windows APIs in the same program.

提供兼容层的是 cygwin1.dll.如果您使用 gcc-3 的 -mno-cygwin 开关或 MinGW 编译器之一构建非 Cygwin 可执行文件,那么您当然不能使用任何 POSIX/Linux 特定的 API,并且任何此类调用都需要替换为 Windows等价物.

It's the cygwin1.dll that provides that compatibility layer. If you build non-Cygwin executables using gcc-3's -mno-cygwin switch or one of the MinGW compilers, then of course you can't use any POSIX/Linux-specific APIs, and any such calls will need to be replaced with Windows equivalents.

这篇关于cygwin下使用GCC生成的可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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