如何在 Cygwin 中执行文件?
如何使用 Cygwin shell 执行 a.exe
?
我在 Windows 上的 Eclipse 中创建了一个 C 文件,然后使用 Cygwin 导航到该目录。 我在 C 源文件上调用 gcc,并生成了 a.exe
。 我想运行a.exe
。
How can I execute a.exe
using the Cygwin shell?
I created a C file in Eclipse on Windows and then used Cygwin to navigate to the directory. I called gcc on the C source file and a.exe
was produced. I would like to run a.exe
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
./a.exe 在提示符下
./a.exe at the prompt
您应该只需输入文件名即可调用它。 您可能必须调用 ./a.exe,因为出于安全原因,当前目录通常不在路径上。
you should just be able to call it by typing in the file name. You may have to call ./a.exe as the current directory is usually not on the path for security reasons.
Unix 在默认情况下已经很长时间没有这样的行为了(所以你可以只写可执行文件名,前面不带 ./)。 它被称为 a.exe,因为否则 Windows 不会执行它,因为它从扩展名获取文件类型。
A Unix hasn't behaved in that way by default (so you can just write the executable name without ./ at the front) in a long time. It's called a.exe, because else Windows won't execute it, as it gets file types from the extension.
托马斯写道:
一般行为不同。 为了让你的程序在 Windows 上运行,它需要以 .exe 结尾,“C 编程语言”并不是为 Windows 程序员编写的。 正如您所看到的,cygwin 模拟 POSIX 环境的许多(但不是全部)功能。
Thomas wrote:
It does in general. For your program to run on Windows it needs to end in .exe, "the C Programming language" was not written with Windows programmers in mind. As you've seen, cygwin emulates many, but not all, features of a POSIX environment.
cygwin 下的 gcc 不会生成“ELF 32-bit LSBexecutable”类型的 Linux 可执行输出文件,但它会生成“PE32executable for MS Windows”类型的 Windows 可执行文件,该文件依赖于 cygwin1.dll,因此需要在 cygwin shell 下运行。 如果您需要在 dos 提示符下独立运行它,则 cygwin1.dll 需要位于您的 Windows 路径中。
-广告。
gcc under cygwin does not generate a Linux executable output file of type " ELF 32-bit LSB executable," but it generates a windows executable of type "PE32 executable for MS Windows" which has a dependency on cygwin1.dll, so it needs to be run under cygwin shell. If u need to run it under dos prompt independently, they cygwin1.dll needs to be in your Windows PATH.
-AD.
要执行当前目录中的文件,要使用的语法是:
./foo
正如allain所提到的,
./a.exe
是执行a的正确方法。使用 Cygwin 在工作目录中运行 exe。注意:您可能希望使用
cc
的-o
参数来指定您自己的输出文件名。 例如:cc helloworld.c -o helloworld.exe
。To execute a file in the current directory, the syntax to use is:
./foo
As mentioned by allain,
./a.exe
is the correct way to execute a.exe in the working directory using Cygwin.Note: You may wish to use the
-o
parameter tocc
to specify your own output filename. An example of this would be:cc helloworld.c -o helloworld.exe
.只需在 shell 中输入 ./a
just type ./a in the shell
当您启动 Cygwin 时,您位于“/home/Administrator”区域,因此请将您的 a.exe 文件放在那里。
然后在提示符下运行:
Cygwin 会读取它并要求您安装它。
When you start in Cygwin you are in the "/home/Administrator" zone, so put your a.exe file there.
Then at the prompt run:
It will be read in by Cygwin and you will be asked to install it.
只需调用它
即可确保它会被找到(路径)。
Just call it
Make sure it will be found (path).