views:

878

answers:

7

I'm looking for just a compiler for C++ (such as g++) for Windows, that I could run in my cmd.

I'm using notepad++ as my text editor and I want to set up a macro in there that can compile my programs for me.

I do not wish to install Cygwin though.

Any suggestions? Thanks in advance :)

+13  A: 

MinGW. It's GCC/G++ for Windows. It's much lighter than Cygwin. The main difference from Cygwin GCC is that it doesn't try to emulate UNIX APIs, you have to use the Windows APIs (and of course the standard C/C++ libraries). It also doesn't provide a shell and utilities like Cygwin, just the compiler.

There is also a related system called MSYS, which provides a shell, etc. like Cygwin, but this is not required. MinGW itself will run in CMD (but I highly suggest using something better like Bash, for your own sanity).

Zifre
Is this just a compiler, or another shell like Cygwin?Works on Vista x64?
hahuang65
Click the link.
jmucchiello
It's a compiler. It *is* GCC itself, ported to Windows. Works on everything Windows.
Zifre
It says it is Bourne shell, an alternative to cmd.exe, which means that this like Cygwin, but just lighter.Are there no compilers that can run natively on cmd.exe?
hahuang65
It _does_ work on cmd.exe. MinGW gives you normal executable tools without any Cygwin-like POSIX-compatible environment. It does include 'bash', but every tool can be ran from cmd.exe.
Eduard - Gabriel Munteanu
In fact MSYS includes 'bash'. MinGW itself is only the toolchain stuff.
Eduard - Gabriel Munteanu
Sounds great, I will give it a try when I get home :)
hahuang65
I just wish Windows was a *nix system :(
hahuang65
+3  A: 

MinGW

jmucchiello
+14  A: 

Visual C++ has a command line compiler, cl:

Greg Hewgill
Um... I'm just wondering, are there any advantages over using MinGW? I'm pretty sure GCC optimizes better (and it is open source).
Zifre
One thing MS does pretty well is dev tools. And the compiler plays very nicely with their various SDKs.
Joe
@Zifre: If one is just starting out on a new project, it doesn't matter as much which one you choose. However, if you are working with an existing body of code that might already be using Visual C++, and you want to start using a command line compiler, then this is clearly the best solution for that situation.
Greg Hewgill
Why should GCC optimise better?
Jean Azzopardi
@Jean Azzopardi: well, because it does. It's simply a more mature compiler. And I do understand using Visual Studio (a great IDE), but I still don't really see any reason to use just `cl`, unless you have legacy software (which it doesn't sound like the OP has).
Zifre
@Zifre - I'd be surprised if GCC optimizes better than MSVC. I'd imagine that some benchmarks would be won by one compiler and other benchmarks would be won by the other compiler. If you have access to numbers that show GCC is clearly better than MSVC I'm sure there are a lot of people who would be interested.
Michael Burr
MS's compiler has got a lot better with 2005 and 2008, their standards compliance is as good as GCC and the performance is very good. The only way to know which is better is to test your specific code. MSVC isn't 2nd best anymore.
Martin Beckett
@Zifre: GCC is not "more mature". Both MSVC and GCC are mature, and each have their advantages. And of course, both are essentially 30 year old code that has been gradually expanded and improved on, to the extent that both are held together with spit and duct tape these days. Maturity is not the issue. Anyway, last I checked, GCC is still not able to do anything like MSVC's COMDAT folding optimization, which really hurts executable size for template-heavy code under GCC. So no, GCC is not "better". It does some things better, and fails at others.
jalf
ALso, MSVC is optimized for x86/x64. GCC needs to support about every CPU ever produced. Jack of all trades, master of none.
MSalters
@Zifre, could you please point me to your empirical evidence supporting GCC optimizing better than MSVC?
mrduclaw
+1  A: 

If you don't have Visual Studio, you can download the Windows SDK (newer version) or the Windows Driver Kit for free, and then use the CL.EXE command-line compiler as suggested by @Greg Hewgill.

crosstalk
+1  A: 

The old Borland C++ non-IDE compiler is freely available:
http://cc.codegear.com/Free.aspx?id=24778

Here is Wikipedia's background on this free, Windows, command-line compiler:
http://en.wikipedia.org/wiki/Borland_C%2B%2B

William Leara
+3  A: 

Digital Mars is excellent.

Joel Lucsy
Um... like `cl`, I can't really see any advantages to this except fast compilation times. It doesn't have good optimization, and, IIRC, it's closed source.
Zifre
The back-end can be found as part of the source for DMD. As for advantages; it's so self contained that its install instructions are 1) unzip 2) edit your path 3) use. Also it will still output almost any Dos/Windows format all the way back to 16-bit .COM files.
BCS
Um... why would you want 16-bit .COM files? People still use DOS?
Zifre
@Zifre: Um do you read The Daily WTF?
BCS
+2  A: 

Probably not what you're looking for, but just to add to the question for completeness, the Intel Optimizing Compiler works great on Windows, Linux and Mac Intel platforms. A bit on the pricey side, but for highly optimized compiles on Intel processors it's second to none.

Gerald
If only it were open source :( It is an *awesome* compiler
Zifre