I am looking for free tools to compile C programs on Windows 7. I've always compiled C code on Ubuntu using gcc in the past. So, how can I compile C code on Windows 7? Please teach me. :)
6 Answers
MinGW uses a fairly old version of GCC (3.4.5, I believe), and hasn't been updated in a while. If you're already comfortable with the GCC toolset and just looking to get your feet wet in Windows programming, this may be a good option for you. There are lots of great IDEs available that use this compiler.
Edit: Apparently I was wrong; that's what I get for talking about something I know very little about. Tauran points out that there is a project that aims to provide the MinGW toolkit with the current version of GCC. You can download it from their website.
However, I'm not sure that I can recommend it for serious Windows development. If you're not a idealistic fanboy who can't stomach the notion of ever using Microsoft software, I highly recommend investigating Visual Studio, which comes bundled with Microsoft's C/C++ compiler. The Express version (which includes the same compiler as all the paid-for editions) is absolutely free for download. In addition to the compiler, Visual Studio also provides a world-class IDE that makes developing Windows-specific applications much easier. Yes, detractors will ramble on about the fact that it's not fully standards-compliant, but such is the world of writing Windows applications. They're never going to be truly portable once you include windows.h
, so most of the idealistic dedication just ends up being a waste of time.

- 239,200
- 50
- 490
- 574
-
-
Considering the state of flux of the standards, is there even such a thing as a fully standards-compliant C++ compiler? – Gabe Apr 17 '11 at 06:21
-
1@Mohd: I was just explaining the two options. I'm anything but an expert on MinGW! I don't even use it myself, to be honest. The website I linked to has most of the information you need. If you're looking for a good IDE, you might try [Code::Blocks](http://www.codeblocks.org/). But any text editor (like [Notepad++](http://notepad-plus-plus.org/) or [Programmer's Notepad](http://www.pnotepad.org/)) will get the job done. – Cody Gray - on strike Apr 17 '11 at 06:22
-
I has use Notepad++ to edit my code. So, how can I compile my code using MinGW? – Mohd Isa Apr 17 '11 at 06:26
-
1@Mohd: Run the compiler from the command line, just like you would in Ubuntu. If you're new to Windows, you can get to a command line by typing `cmd` in the search box in the Start menu, and pressing Enter. Most things should work just like GCC on Ubuntu. See the [FAQ on Getting Started with MinGW](http://www.mingw.org/wiki/Getting_Started), and the [guide to compiling apps for first time users](http://www.mingw.org/wiki/MinGWforFirstTimeUsers). – Cody Gray - on strike Apr 17 '11 at 06:28
-
@Cody thanks for helping me, I will try it. I need study it first. Any problem, I will ask you. Thanks again Cody. – Mohd Isa Apr 17 '11 at 06:33
-
@Cody I has run gcc using MinGW in Windows, why it is relatively slow compared to gcc in Ubuntu? – Mohd Isa Apr 17 '11 at 07:15
-
@Mohd: I have no idea. A Google search indicates that that might be a known problem with MinGW. I assume it has something to do with it being a port to Windows, but I don't know enough about the technical details to say for sure. Microsoft's compiler (bundled with Visual Studio) is at least as fast as GCC on Ubuntu, but compiling C code is generally not that fast. Also, having optimizations turned on can slow down the compile—check the command line switches that you're passing. – Cody Gray - on strike Apr 17 '11 at 07:19
-
@Cody: Never mind, although slowly it is still functioning. I want to ask, how to compile Perl code? Can it run with MinGW? – Mohd Isa Apr 17 '11 at 07:27
-
@Mohd: I don't know anything at all about Perl. You should create a new question to ask about that. – Cody Gray - on strike Apr 17 '11 at 07:32
-
-
Not true, you can get Mingw with gcc 4.6 already! E.g. http://mingw-w64.sourceforge.net/ – tauran Apr 17 '11 at 07:58
-
"However, I'm not sure that I can recommend it for serious Windows development. If you're not a idealistic fanboy who can't stomach the notion of ever using Microsoft software" - Stupid FUD. – tauran Apr 17 '11 at 08:02
-
@tauran: That's good to know! I've updated my answer with your link. Erm, what's that next comment about? I don't know what "FUD" means, but I gather that you're somehow offended by what I said? I'm not sure how that's possible; the only way you can be offended is if you classify *yourself* as a fanboy, in which case, me calling you one can hardly be considered offensive... – Cody Gray - on strike Apr 17 '11 at 08:04
-
I am not offended but how can you **not** recommend it, if you "know very little" about it? Your answer is classical FUD: http://en.wikipedia.org/wiki/Fear,_Uncertainty_and_Doubt – tauran Apr 17 '11 at 08:10
-
@tauran: It's none of that. I know very little about actually *using* MinGW on a day-to-day basis, because I don't; I know plenty about GCC. More importantly, the Visual Studio toolset is just much more rich and productive when your goal is developing Windows apps. – Cody Gray - on strike Apr 17 '11 at 08:13
-
Why is it **much** more rich? What is so much better than for example Eclipse CDT (IDE), MinGW and Qt (GUI toolkit) bundled together? Also note that I already used both setups professionally while you seem to know only one but still give a judgement... – tauran Apr 17 '11 at 08:21
-
3@tauran: I'm not interested in your flamewar. Start a new question if you'd like to know the difference. Alternatively, post your own answer and state your opinions. – Cody Gray - on strike Apr 17 '11 at 08:28
-
Well I was just interested in reasons/facts/experience for **your** opinion, but if you don't want to state them, so be it. :) – tauran Apr 17 '11 at 08:36
-
-
@tauran I am, how to use MinGW to compile Perl code? Please refer this question: http://stackoverflow.com/questions/5692266/can-we-use-mingw-to-compile-perl-script – Mohd Isa Apr 17 '11 at 10:21
-
Do try to avoid starting an argument with me and all, but isn't cygwin a viable compiler too? It is possible that cygwin is something other than that, I work with python which has zero compiling (with the exception of pyinstaller) so I wouldn't really know but when you search GCC for windows mingw and cygwin are the two main results... – trevorKirkby Oct 24 '14 at 01:18
Microsoft Visual Studio Express
It's a full IDE, with powerful debugging tools, syntax highlighting, etc.

- 9,624
- 19
- 56
- 74
-
I had a tough time trying to compile C files using VC++ 2010. I kept getting the error `LINK : fatal error LNK1104: cannot open file 'MSVCRT.lib'`. I couldn't fix easily it despite Googling - trying to fix it was leading to other errors. I gave up and installed Dev C++, which uses the MinGW compiler (I'm on XP). – AbdullahC Apr 17 '11 at 07:14
-
@Hippo: My guess is that all you needed to do was tell the linker where to find `MSVCRT.lib`. It's bundled with an installation of Visual Studio, but doesn't work on the command line out of the box because it's location is not in your `LIBPATH`. See the answers to [this question](http://stackoverflow.com/questions/927574/compiling-c-program-causes-fatal-error-lnk1104). – Cody Gray - on strike Apr 17 '11 at 07:23
-
@Cody Gray: Thanks for your helpful response. I have this problem with the IDE. Looking in `C:\Program Files\Microsoft Visual Studio 10.0\VC\lib`, I see that the .lib files are missing, but Google Desktop's cache shows them. I'll do a reinstall and let you know if it works :) – AbdullahC Apr 17 '11 at 07:36
-
@Hippo: Yup, I'd start with a reinstall first. If that doesn't fix the problem, you might need to download the Windows SDK. You can [grab the latest version here](http://msdn.microsoft.com/en-us/windows/bb980924). It's usually included with Visual Studio, and it's best to use the one that came with it if possible, but it can be obtained separately if necessary. – Cody Gray - on strike Apr 17 '11 at 07:37
If you are familiar with gcc, as you indicated in the question, you can install MinGW, which will set a linux-like compile environment in Win7. Otherwise, Visual Studio 2010 Express is the best choice.

- 553
- 1
- 6
- 8
-
I don't know how to use Visual Studio 2010 Express. How to compile C programming with it? – Mohd Isa Apr 17 '11 at 09:43
-
1First, create a empty (c++ console) project. Second, create a new c or c++ file and type or just paste your c code in this newly-created file. Press compile & build button in the tools bar and then press the run button. – demoslam Apr 17 '11 at 13:51
Compiling Programs on Windows 7:
You have to download configured Borland Compiler from http://www.4shared.com/get/Gs41_5yA/borland_for_graphics.html or http://dwij.co.in/graphics-c-programming-for-windows-7-borland-compiler/.
Put your Borland’s ‘bin’ folder into Environmental Variables.
Now go inside folder ‘bin’ & edit file bcc32.cfg as per your folder structure. This file contains settings of headers & libraries.
-I"D:\Borland\include;"
-L"D:\Borland\lib;D:\Borland\Lib\PSDK"
Now create any C/C++ Program say myprogram.cpp
Use following command to compile this bunch of code:
F:\>bcc32 myprogram.cpp

- 122,561
- 47
- 239
- 335

- 2,000
- 18
- 21
Get gcc for Windows . However, you will have to install MinGW as well.
You can use Visual Studio 2010 express edition as well. Link here

- 14,882
- 6
- 45
- 69
-
How to run it? I mean, I has try to install it. But I don't know how to run. – Mohd Isa Apr 17 '11 at 06:00
-
There are already some discussions here on SO regarding this: For example, look at this link.. http://stackoverflow.com/questions/2368430/using-gcc-with-mingw – Aamir Apr 17 '11 at 06:03
-
-
-
I use the Ruby developers kit, it has GCC and MinGW and is just a zip you download from http://rubyinstaller.org/downloads/ (at the end of the page) and extract, no installation needed, compiling the .c program is as simple as gcc -o hello.exe hello.c , see https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html for more info – peter Nov 26 '16 at 15:26
You can get MinGW (as others have suggested) but I would recommend getting a simple IDE (not VS Express). You can try Dev C++ http://www.bloodshed.net/devcpp.html Its a simple IDE for C/C++ and uses MinGW internally. In this you can write and compile single C files without creating a full-blown "project".

- 6,974
- 5
- 30
- 43