C/C++ Compiler Setup and Single Line Build and Run Command
The most common C/C++ compilers are the GCC and G++ compilers contained in the MinGW suite. In order to run and test our C/C++ code we need a compiler to link and create our executable files. MinGW includes the GCC and G++ compilers and can be downloaded here. Install MinGW in any folder you'd like such as
Next right-click on My Computer on your desktop or Computer in your Start Menu and go to Properties. You may also search for Advanced System Settings in the Start Menu. In order to execute GCC and G++ in the command prompt from our working directory that contains our source files we need to add the path to mingw\bin to our system. From here you may click Advanced System Settings then Environment Variables. Under the System variables box double-click Path and add
with a semicolon to separate each path. Now open a command prompt and type
You should now have installed the GCC and G++ compiler correctly. The correct syntax to Build and Run our source files on the command line looks like this:
gcc file.c -o file.exe && file.exe
What this does is execute the GCC compiler then send it our source file, send it a flag of -o to name our output file and then execute our created executable. You can find more options and ways to manipulate the GCC compiler here.