This tutorial will run through using g++ on DSC machines. If you're writing a pure C application, all of the following also applies to gcc.
Click on any image to view it in a lightbox.
For starters, let's get MinGW/g++ to compile and run the eponymous hello world program. The first thing to do is navigate to your preferred source code storage location, and write the hello world program.
Then, start MinGW.
And then navigate the MinGW shell so that its working directory is your program location.
At this point, you can run the g++ compiler on your program to generate an executable.
Then, run the executable. You may run it from inside MinGW. However, since it's a native Windows exectuable, you may also run it from the command prompt, from a batch script, or by double clicking on the executable in the explorer window. For this program, running it from the explorer window merely flashes a console window.
At some point you may build up a code library that you would like to reference. g++ contains options to ease the reuse of old code. In order to explore these options, lets compute the factorial of five. First, go to your prefered source directory, and write the program. The program is split up into three files: one that contains a factorial algorithm, coupled with a header file, and one that makes use of that module. The files are split into disparate directories.
Start up MinGW, and navigate it to the directory containing the factorial function (Whee.*). Then, compile the Whee.cpp file without linking (the -c option). This will produce one object file, Whee.o, that is ready to be linked into some other program.
Then, navigate to the directory containing the main program (FacFive.cpp). Then compile it without linking. In order to compile, g++ will need to know where any external code libraries are. The -I option can be used for this.
Finally, link all the object files together, specifying the name of the executable with the -o option. While this example does not use any dll libraries, if your own code uses them, you'll need to use the -L option. Run the program, and you should find that 5! = 120.