[英]How can I compile C files into an executable (.exe) file?
I am unsure about compiling C files into executables by using Cygwin under Windows 7.我不确定在 Windows 7 下使用 Cygwin 将 C 文件编译成可执行文件。
Can anyone please tell me how to do this?谁能告诉我如何做到这一点?
I've read some tutorials but still don't get it.我已经阅读了一些教程,但仍然不明白。 I understand that I need a Makefile, but what shall I write into it to have an executable file after the compilation process?
我知道我需要一个 Makefile,但是在编译过程之后我应该在其中写入什么以获得可执行文件?
For the beginning I would say it is enough to Install MinGW.一开始我会说安装MinGW就足够了。 If you have installed it you find in the bin folder a gcc.exe which is the Compiler.
如果你已经安装了它,你会在 bin 文件夹中找到一个 gcc.exe,它是编译器。 Either set the PATH Variable to the bin folder or go directly to this folder.
将 PATH 变量设置为 bin 文件夹或直接转到此文件夹。 In terminal use:
在终端使用:
gcc your_C_file.c
The output will be an exe.输出将是一个 exe。
Q: How can i compile c-files into an executable (.exe) file?问:如何将 c 文件编译为可执行 (.exe) 文件?
A: Get and use a C compiler.答:获取并使用 C 编译器。
GCC/Cygwin is one possibility. GCC/Cygwin 是一种可能性。 MS Visual Studio is another: you can download the free "MSVS Express" here: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express .
MS Visual Studio 是另一个:您可以在这里下载免费的“MSVS Express”: http : //www.microsoft.com/visualstudio/en-us/products/2010-editions/express 。
How you interact with the compiler is another question.您如何与编译器交互是另一个问题。
You can certainly use a command line.您当然可以使用命令行。
You can use a command line with or without "Make": you can let "Makefiles" do the "heavy lifting" for you, you can use .bat files, or you can type everything by hand.您可以使用带或不带“Make”的命令行:您可以让“Makefiles”为您完成“繁重的工作”,您可以使用 .bat 文件,或者您可以手动键入所有内容。
Using a graphical IDE is another possibility.使用图形 IDE 是另一种可能性。 "Eclipse" and "MS Visual Studio" are two popular alternatives for Windows.
“Eclipse”和“MS Visual Studio”是 Windows 的两种流行替代品。
There are several ways to compile c-files.有几种方法可以编译 c 文件。 Makefiles are just one possibility.
Makefile 只是一种可能性。 But as you proposed it... Here are two tutorials for Makefiles:
但是正如你提出的那样......这里有两个关于 Makefile 的教程:
But note, that you will also need a compiler (installed under cygwin).但请注意,您还需要一个编译器(安装在 cygwin 下)。
Another possibility is to use Dev-C++, a IDE (Integrated Developement Environment) for C++.另一种可能性是使用 Dev-C++,一种用于 C++ 的 IDE(集成开发环境)。 Once installed you can create a project and add your source code, and just compile the project.
安装后,您可以创建一个项目并添加源代码,然后编译该项目。 It also contains a c++ compiler (also supports C), which is named mingw.
它还包含一个名为 mingw 的 C++ 编译器(也支持 C)。 The makefile needed is automatically generated.
所需的 makefile 是自动生成的。 So that's simpler for beginners.
所以这对初学者来说更简单。
You can download Dev-Cpp here: http://www.bloodshed.net/devcpp.html你可以在这里下载 Dev-Cpp: http : //www.bloodshed.net/devcpp.html
Note: As you spoke about cygwin I assume you use Windows.注意:当您谈到 cygwin 时,我假设您使用的是 Windows。 Dev++ works only under windows, and you wont need cygwin.
Dev++ 只在 windows 下工作,你不需要 cygwin。
Even easier solution is A86 Assembler.更简单的解决方案是 A86 Assembler。 Its old school but works perfectly, in the right hands ;)
它的老派,但在正确的人手中工作得很好;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.