How can I compile C files into an executable (.exe) file?

岁酱吖の 提交于 2019-12-10 16:27:41

问题


I am unsure about compiling C files into executables by using Cygwin under Windows 7.

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?


回答1:


There are several ways to compile c-files. Makefiles are just one possibility. But as you proposed it... Here are two tutorials for Makefiles:

  1. http://makepp.sourceforge.net/1.19/makepp_tutorial.html
  2. http://mrbook.org/tutorials/make/

But note, that you will also need a compiler (installed under cygwin).

Another possibility is to use Dev-C++, a IDE (Integrated Developement Environment) for C++. 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. The makefile needed is automatically generated. So that's simpler for beginners.

You can download Dev-Cpp here: http://www.bloodshed.net/devcpp.html

Note: As you spoke about cygwin I assume you use Windows. Dev++ works only under windows, and you wont need cygwin.




回答2:


For the beginning I would say it is enough to Install MinGW. If you have installed it you find in the bin folder a gcc.exe which is the Compiler. Either set the PATH Variable to the bin folder or go directly to this folder. In terminal use:

  gcc your_C_file.c

The output will be an exe.




回答3:


Q: How can i compile c-files into an executable (.exe) file?

A: Get and use a C compiler.

GCC/Cygwin is one possibility. MS Visual Studio is another: you can download the free "MSVS Express" here: 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.

Using a graphical IDE is another possibility. "Eclipse" and "MS Visual Studio" are two popular alternatives for Windows.



来源:https://stackoverflow.com/questions/11956597/how-can-i-compile-c-files-into-an-executable-exe-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!