简体   繁体   English

如何将 C 文件编译为可执行 (.exe) 文件?

[英]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 的教程:

  1. http://makepp.sourceforge.net/1.19/makepp_tutorial.html http://makepp.sourceforge.net/1.19/makepp_tutorial.html
  2. http://mrbook.org/tutorials/make/ (Content from 2012 accessable via waybackmachine ) http://mrbook.org/tutorials/make/(2012 年的内容可通过waybackmachine访问)

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.

相关问题 在C语言中,我如何编译然后创建一个带有标头和两个c文件的可执行文件? - In C how do I compile and then create an executable file with a header and two c files? 如何将C / C ++编译为CP / M-86可执行文件(CMD) - How can I compile C/C++ to a CP/M-86 executable (CMD) 无法在ntfs格式化分区上从.c文件编译可执行文件 - Can't compile executable from .c file on ntfs formated partition 如何从C代码创建工作的可执行文件(.exe) - How to create a working Executable file (.exe) from a C code 当我编译.c文件时,它总是创建名称为'a'的.exe文件。 - When I compile .c file it always creates .exe file with name 'a' 如何一起编译头文件和C文件? - How can I compile a header file and a C file together? 如何为另一台计算机编译Linux可执行文件? - How can I compile a Linux executable for a different machine? 如何获得 gcc.exe 可执行文件来运行也是可执行文件的 arguments? pkg-config.exe 作为命令行参数? - How can I get gcc.exe executable to run the arguments which are also an executable? pkg-config.exe as a command line argument? 如何将可执行文件编译为另一个文件(不是源) - How to compile executable into another file(Not source) 如何将文件捆绑/包含并使用到 C - linux 中的可执行文件中? - How do I bundle/include and use files into an executable in C - linux?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM