C and C++ are popular programming languages that quickly provide access to making formula's and solving complex issues with minimal resources expended. The issue is finding a way to compile and make the program executable.
One of your options may be using Visual Studio, which is a text-editor, compiler in one. While useful, some may find it too complex or want a simpler way to modify and compile their code. That's where Minimalist GNU for Windows comes in, or MinGW for short. You use MinGW in your command line interface, the text only application you can quickly access by pressing the windows key and typing in "cmd".
By the end of this Instructable, you should have MinGW properly installed, and be able to compile any c/c++ program anywhere on your computer.
NOTE: This instructable is purely for Windows environments. Linux comes with GCC, a GNU collection of compilers. This is the desired result for our environment, to get GCC onto Windows.
You'll need a computer to download the software and a decent internet connection for a stable and swift installation. While not required, you may also want a thumbdrive, in case you want to have a physically portable copy of MinGW setup.
The first thing we need to do is get the installer.
To do that, we need to go to the MinGW website.
From there, you will want to go to the downloads link, located on the left side in the navigation section. In case you cannot find it or it's moved, this link will take you there
What we want is the mingw-get-setup.exe file. Once the file has downloaded, we can move on to the next step.
The first thing it asks is where you want to install it. To keep it easy to access, I recommend leaving it in the default directory. Otherwise, you can set this up anywhere, even on thumb drives.
The next option talks about the User Interface for MinGW. We will work with a UI in this case, as it's better to see what we can do.
Now that we've finished the installation of MinGW, we have to pick specific packages to install. In this instructable, we are going to keep it simple and work with the basic set up, as we can get the desired result without having to delve into all of the individual packages that MinGW offers.
In the left Table of Contents, make sure you are looking at Basic Setup. From there you should see 7 items in the right table. For C/C++ compilers, you will want to install the following packages: mingw32-base-bin and mingw32-gcc-g++-bin. GCC is used for c programs, and G++ is used for C++ programs.
To install a package, right click the package and then click "Mark for Installation". Once you've marked the packages you want, go to the top left and click on "Installation". You will then "Apply Changes," which will then show you a new window that shows the changes you will make. Click "Accept" and the installation will then begin. A download will begin, and then another window will appear, this time showing you if your installation is finished.
With your newly installed compiler, you'll notice that your command prompt doesn't recognize gcc or g++ as commands. In order to do this you must do the following:
Now you have the ability to make programs and compile them anywhere on your system.
To compile a program, all you have to do is call gcc if its a c program, or g++ if it's a c++ program, and then type in the name of the program you want to compile. Example: gcc helloworld.c or g++ helloworld.cpp
The next step, while optional, does explain some useful options you can use with your compiler.
While not required for compiling your programs, these options will help you in debugging your code.
The syntax for how you put these options in are as follows for either gcc or g++: g(cc/++) -option argument