121

I have MinGW on my windows 7 machine. I wish to install and use complete gcc for C compiler. I found there is no single pre-compiled ready-made installation file for this purpose. I checked the following page : http://gcc.gnu.org/install/ It is difficult and I find it above my level of understanding. Could any one please provide me step by step guidance along with links?

KawaiKx
  • 9,558
  • 19
  • 72
  • 111
  • This is one of the best tutorials I found, [How to Install MinGW GCC G++ Compiler on Windows 10 or 11](https://www.youtube.com/watch?v=2bZfdWCMBMI), hope it helps. – InfiniteStack Nov 14 '22 at 02:16

5 Answers5

96

EDIT Since not so recently by now, MinGW-w64 has "absorbed" one of the toolchain building projects. The downloads can be found here. The installer should work, and allow you to pick a version that you need.

Note the Qt SDK comes with the same toolchain. So if you are developing in Qt and using the SDK, just use the toolchain it comes with.

Another alternative that has up to date toolchains comes from... harhar... a Microsoft developer, none other than STL (Stephan T. Lavavej, isn't that a spot-on name for the maintainer of MSVC++ Standard Library!). You can find it here. It includes Boost.

Another option which is highly useful if you care for prebuilt dependencies is MSYS2, which provides a Unix shell (a Cygwin fork modified to work better with Windows pathnames and such), also provides a GCC. It usually lags a bit behind, but that is compensated for by its good package management system and stability. They also provide a functional Clang with libc++ if you care for such thing.

I leave the below for reference, but I strongly suggest against using MinGW.org, due to limitations detailed below. TDM-GCC (the MinGW-w64 version) provides some hacks that you may find useful in your specific situation, although I recommend using vanilla GCC at all times for maximum compatibility.


GCC for Windows is provided by two projects currently. They both provide a very own implementation of the Windows SDK (headers and libraries) which is necessary because GCC does not work with Visual Studio files.

  1. The older mingw.org, which @Mat already pointed you to. They provide only a 32-bit compiler. See here for the downloads you need:

    • Binutils is the linker and resource compiler etc.
    • GCC is the compiler, and is split in core and language packages
    • GDB is the debugger.
    • runtime library is required only for mingw.org
    • You might need to download mingw32-make seperately.
    • For support, you can try (don't expect friendly replies) mingw-users@lists.sourceforge.net

    Alternatively, download mingw-get and use that.

  2. The newer mingw-w64, which as the name predicts, also provides a 64-bit variant, and in the future hopefully some ARM support. I use it and built toolchains with their CRT. Personal and auto builds are found under "Toolchains targetting Win32/64" here. They also provide Linux to Windows cross-compilers. I suggest you try a personal build first, they are more complete. Try mine (rubenvb) for GCC 4.6 to 4.8, or use sezero's for GCC 4.4 and 4.5. Both of us provide 32-bit and 64-bit native toolchains. These packages include everything listed above. I currently recommend the "MinGW-Builds" builds, as these are currently sanctioned as "official builds", and come with an installer (see above).

    For support, send an email to mingw-w64-public@lists.sourceforge.net or post on the forum via sourceforge.net.

Both projects have their files listed on sourceforge, and all you have to do is either run the installer (in case of mingw.org) or download a suitable zipped package and extract it (in the case of mingw-w64).

There are a lot of "non-official" toolchain builders, one of the most popular is TDM-GCC. They may use patches that break binary compatibility with official/unpatched toolchains, so be careful using them. It's best to use the official releases.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • 6
    your answer looks certainly complete but I don't get all of it. lot of terms in your answer are new to me.. My intention is to get gcc c compiler, linker, header files and library files. I have downloaded your personal build for GCC 4.6. now what do I do next? please tolerate with me :-) – KawaiKx Jun 18 '11 at 12:49
  • 9
    @Saurabh: no problem, I tried to be correct in terms of words. You now extract the package, to for example `C:\` so that `C:\mingw64\bin` (or C:\mingw32\bin`) contains `gcc.exe`. Then, open a cmd.exe command prompt, and execute `set PATH=C:\mingw64\bin;%PATH%`. Then you will be able to call mingw32-make, gcc, gdb, etc from that commandline. Programs using it (like cmake, Qt Creator, Codeblocks) also need it in PATH. In case you need a system/user-wide PATH change, go to Control Panel->System->Advanced->Environment variables, and add or modify PATH there. – rubenvb Jun 18 '11 at 13:12
  • 1
    done that. its working well. thanks a lot.. why there is so much hassle in installing gcc compiler on windows machine? was it not meant for x86 platform originally? – KawaiKx Jun 18 '11 at 14:56
  • 4
    There are at most 4-5 developers concerned with GCC/binutils for Windows. They do an great job, but leave it to the community to deliver their tools. Don't understand wrong here: TDM has been around a long time and provides a handy installer, but he doesn't submit patches upstream due to copyright issues. Codeblocks delivers a MinGW toolchain with the IDE, so does Qt. But none of them deliver 64-bit :). Building GCC itself requires a Unix environment, like Cygwin/MSYS, or even better: Linux. The build process is not straightforward. But it's not much hassle to install once you know what to do. – rubenvb Jun 18 '11 at 15:03
  • 1
    @rubenvb, I noticed that Mingw64 now has an installer that allows you to pick stuff out. Is this a worse idea than getting a personal build? – batbrat Feb 07 '14 at 06:23
  • 1
    batbrat: The installer is for the "MinGW-Builds", which are the official MinGW-w64 binary toolchain packages, since I stopped updating mine. I recommend using them. – rubenvb May 23 '14 at 07:04
  • Link (http://mingw-w64.sourceforge.net/download.php#mingw-builds) is dead – Stan Strum Feb 15 '18 at 01:49
26

Download mingw-get and simply issue:

mingw-get install gcc.

See the Getting Started page.

Mat
  • 202,337
  • 40
  • 393
  • 406
  • 2
    this installation does not install gcc standard C library.. instead it uses msvcr***.a. why so? is it because gcc standard C library contains object codes meant for non-x86 chips? – KawaiKx Jun 18 '11 at 12:52
  • 3
    because the MinGW port of GCC on windows uses the windows standard C library. If you want to use another C library, look at cygwin (uses newlib). Not sure you'll have much luck getting GLIBC on Windows (I don't really see the point either). – Mat Jun 18 '11 at 12:56
  • 1
    what do you mean by "MinGW port of GCC on windows"exactly? sorry, it may sound stupid but I am new to these terms.. – KawaiKx Jun 18 '11 at 14:02
  • 2
    That means the version of GCC produced by MinGW to run on and target windows environments. – Mat Jun 18 '11 at 14:06
12
  1. Extract the package to C:\ from here and install it

  2. Copy the path C:\MinGW\bin which contains gcc.exe.

  3. go to Control Panel->System->Advanced>Environment variables, and add or modify PATH. (just concatenate with ';')

  4. Then, open a cmd.exe command prompt (Windows + R and type cmd, if already opened, please close and open a new one, to get the path change)

  5. change the folder to your file path by cd D:\c code Path

  6. type gcc main.c -o helloworld.o. It will compile the code. for C++ use g++

7 type ./helloworld to run the program.

If zlib1.dll is missing, download from here

Vinoj John Hosan
  • 6,448
  • 2
  • 41
  • 37
6

Following up on Mat's answer (use Cygwin), here are some detailed instructions for : installing gcc on Windows The packages you want are gcc, gdb and make. Cygwin installer lets you install additional packages if you need them.

michaelok
  • 1,124
  • 1
  • 13
  • 20
  • I installed Cygwin and required packages. I also verified from Windows command line that gcc, gdb and make are accessible. But still installation of rails gem fails with same error! Has anyone tried the Cygwin and Rails on Windows successfully? – Vishal Biyani Jun 28 '13 at 08:10
  • Also, when I run `gcc` on command prompt, I get access denied, not sure why – Vishal Biyani Jun 28 '13 at 08:14
  • 3
    Nowadays, I'd probably go with something like Oracle's VirtualBox (https://www.virtualbox.org/) or VMWare instead of Cygwin. Then you can run both OSes on the same machine. As for Rails, have you tried Rails Installer? http://railsinstaller.org/ – michaelok Jul 11 '13 at 20:08
  • Thanks for the tip @michaelok, will try that for sure – Vishal Biyani Jul 22 '13 at 12:55
  • I couldn't find it either, so I updated it to the main Cygwin page. What is tricky about the installer is making sure you are selecting the right packages. From the instructions, which has this to say about gcc: "By default, setup.exe will install only the packages in the Base category and their dependencies, resulting in a minimal Cygwin installation. However, this will not include many commonly used tools such as gcc (which you will find in the Devel category)" – michaelok Dec 04 '14 at 21:24
  • @michaelok, thanks for fair last comment, it should lead to remove "easily" from your answer ;) still don't know how to install gcc on Windows... continue searching... – Andrzej Martyna Mar 27 '18 at 20:31
1

I use msysgit to install gcc on Windows, it has a nice installer which installs most everything that you might need. Most devs will need more than just the compiler, e.g. the shell, shell tools, make, git, svn, etc. msysgit comes with all of that. https://msysgit.github.io/

edit: I am now using msys2. Msys2 uses pacman from Arch Linux to install packages, and includes three environments, for building msys2 apps, 32-bit native apps, and 64-bit native apps. (You probably want to build 32-bit native apps.)

https://msys2.github.io/

You could also go full-monty and install code::blocks or some other gui editor that comes with a compiler. I prefer to use vim and make.

Sam Watkins
  • 7,819
  • 3
  • 38
  • 38
  • Does msysgit still work for you? That URL redirects to [Git for Windows](https://git-for-windows.github.io/) where I see no mention of gcc. I've had bad luck with Git for Windows, but that may be another story. Also there is the [message](https://github.com/msysgit/msysgit) "msysGit has been superseded by Git for Windows 2.x" – Bob Stein Mar 06 '16 at 14:01
  • I am now using msys2 rather than msysgit. https://msys2.github.io/ I updated my answer. – Sam Watkins Mar 07 '16 at 01:30