New to MinGW? What you should first know
Are you new to Mingw? You know nothing about Unix? What is MSYS?
These are common questions for anyone starting out in the programming world. Reading this may help you.
Probably you reached here because you want a good and free compiler for Microsoft Windows.
And yes, here you have it. Don't get disturbed by so many technical subjects. By now, you don't need them.
Mingw uses the great GCC (GNU Compiler Collection). GCC was born in Unix world. Using it in Windows "as is" is not possible, because these Operating Systems (OS) differ in the way they manage data internally and externally. So many files from GCC must be adapted to be used in Windows. And this is what Mingw is for. Many thanks to all the people who donate this effort. Other approach is that from Cygwin: emulate Unix style. Cygwin emulates a POSIX layer and provides its own runtime libraries licensed as GNU GPL instead of working directly with runtime libraries already available on Windows or with less restrictive (non-GPL) licensing.
Download and extract
Because there are many things to use (compiler, linker, utils, API, etc.) you need to download several files:
|mingwrt||the Mingw Runtime system|
|w32api||the Windows Application Programming Interface|
|binutils||linker, profiling, windows resources, etc.|
|make||which gathers all "things to do" to achieve your program|
|gdb||a great debugger to look inside your app while it is running|
The complete name for each file to download includes its version.
You can also download the MinGW-xxx.exe file, and let it download the rest, but probably it doesn't download the last version of each file. The new mingw-get intaller will improve this situation when it becomes available.
Files are compressed in Unix style: .tar.gz
Use an un-zip app (7-Zip is really good: www.7-zip.org ) and extract all of it to your desired directory, usually c:\mingw. Caution: never install MinGW into any directory which includes spaces in its absolute path name.
Some sub-dirs are created. Some files may overwrite other ones. Usually they are license repeated files. No problem: just choose the newer over the older.
If you just learned to write some code and push the "run" icon you may get lost with so many new concepts. Well. Here's a bit of explanation:
You develop your app writing code and splitting it in some files. You also create icons. And perhaps new cursors.
- Each file you create (or re-use) must be analysed, understood, translated to machine-code and even optimized. That's work for the compiler.
- Your icons and cursors will be managed by the windows resources manager (winres.exe).
- All "translated units" (compiled) must be joined. Time for the linker.
- During execution, any app must communicate with OS (which is what really uses CPU, memory and other devices) using the Runtime system.
- To get the OS utilities (say a control, a dialogue, http services, etc.) API must be used.
You surely need special files with functions made by others: libraries. Typically these are the .dll files your app loads at runtime ("dynamic loading" or "shared linking"). But you can also make them part of your .exe file ("static linking"). You can find these special files (.a) in \lib dir.
By now (April 2010) your app will need the file mingwm10.dll. This file is for multi-threading and will not be statically linked into your .exe file. Multi-threading is an expert way of getting more from the CPU. It simulates (or uses) several cores working simultaneously.
All of this building process can be described in a file (say mybuild.file). And you can call it using mingw32-make.exe.
To run your app in a way you can pause it and look at some variables of your code (debugging), use gdb.
If you want to know where your app spends more time (profiling), use gprof. If you want to be alerted as to where to find an error in your code when a program you compiled with MinGW crashes, use a Just in Time debugger such as DrMingw .
Most of this utilities have "parameters" or "flags" or "command switches" when you invoke them. For example, you can ask gcc to generate code optimized for a special CPU, or tell it where to look for (include) other files. You can read gcc/cpp/gprof/etc. documentation on the web (i.e. http://gcc.gnu.org) .
You call make (or each component, one by one) typing it in a command-box.
I'm sure you are asking "Good. But what about pushing the run button?"
For that you need an IDE (Integrated Development Environment). MinGW doesn't incorporate one. You can find many on the web. There are IDE's that include also compilers (as MS Visual Studio).
I recommend Code::Blocks (www.codeblocks.org ). It's good and free. And it's built with MinGW :) If you also install MinGW, C::B can use it automagically, debugging included.
What is MSYS?
It is a Unix-like command line shell.
Unix has some utilities (configure, sed, grep, etc.) you can use in this "box".
Some people develop their apps preparing a make-file that only works well if it's invoked from a Unix shell.
If you want to check out other libraries commonly used by Open Source compiled using MinGW, especially those built in the MSYS environment, see the information on Libraries and Tools .