To compile to .exe open the command prompt and type this:
gcc fileName.c - compiling and linking, produces a.exe
or
gcc -c fileName.c - only compiling, produces fileName.o object file
gcc -o test filename.o - linking and produces test.exe
If there are more than 1 source file you can do the just compiling part for all files and generate object files.Then do the linking by adding their names in the command.Of curse this is applicable if there are less files but for a bigger project you have to write a makefile.
Answer from Korsarq on Stack OverflowI am new to programming and I made a basic program in C. How would I turn it into an exe. I tried GCC, but I was unable to successfully install it.
Videos
To compile to .exe open the command prompt and type this:
gcc fileName.c - compiling and linking, produces a.exe
or
gcc -c fileName.c - only compiling, produces fileName.o object file
gcc -o test filename.o - linking and produces test.exe
If there are more than 1 source file you can do the just compiling part for all files and generate object files.Then do the linking by adding their names in the command.Of curse this is applicable if there are less files but for a bigger project you have to write a makefile.
You are searching for a compiler, like GCC or Clang. If you are developing on Windows, I recommend MinGW (GCC for Windows). Then you can compile and link your source code to an .exe file using the commandline, just like you did on linux.
Your IDE (like Visual Studio) is basically doing the same, you just don't see it. If your IDE is configured properly, it should work just fine.
You can cross-compile from another platform, e.g. using MinGW on another OS such as Linux or Mac OS X, but ultimately you need a compiler somewhere.
If you don't actually need a .EXE per se, but just want to compile and run some C code without having to install a compiler, e.g. for educational/experimental purposes, then there are very useful sites such as codepad.org and ideone.com which provide this capability for C and a number of other languages.
If you are really crazy it is possible. You would need an hexadecimal editor and assembly knowledge. Then you could play the "human compiler" game, transforming C into assembly and putting the opcodes in the hex editor. To learn something it might be useful but in the general case really use a compiler!
How do I compile my .c file into a .exe executable?
The .NET Framework which ships with every modern version of Windows (and will probably be installed even on older versions) includes a command-line C# compiler called csc.exe. You can build your exe with this.
Here are some instructions for using it:
- MSDN: Command-line Building With csc.exe
The csc.exe executable is usually located in the
Microsoft.NET\Framework\<version>folder under the system directory.
Also, if you have the full version of .NET 4.0 (not client profile), you will probably have msbuild.exe in the same place. This is even easier to use, as you can simply pass it a Visual Studio solution file and it will build the whole solution for you, the same way Visual Studio does (apart from some special project types like installers).
There are some related sites, which may help you ..
http://www.ideone.com
http://www.compilers.net
http://www.chami.com/html-kit/devtools
http://www.icsharpcode.net
http://www.recursionsw.com
http://eli-project.sourceforge.net
http://www.openwatcom.com/index.php/Main_Page
http://ccache.samba.org/
http://codepad.org/
http://llvm.cs.uiuc.edu/DPJ/Home.html
http://www.coderun.com/
http://www.db4o.com/
http://docs.codehaus.org/display/JANINO/Home
http://xacc.wordpress.com/
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.
There are several ways to compile c-files. Makefiles are just one possibility. But as you proposed it... Here are two tutorials for Makefiles:
- http://makepp.sourceforge.net/1.19/makepp_tutorial.html
- http://mrbook.org/tutorials/make/ (Content from 2012 accessable via waybackmachine)
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.
I recently learned to create, read and append files in C and I was wondering if it’s possible to get a C program to create another executable, pre-compiled file when it’s run. I’m guessing I would need to write and compile the second file first but after that how do I enter the machine code instructions inside the initial C source code for it to write that file as an exe?