0

I intent to write simple programs in c/c++ that would be run in console. I will be writing code in Notepad++ so I do not need an IDE. What I need is a compiler that will produce a standalone EXE file that would run on any 2000/XP/Vista/7 system without need for installing VC9/cygwin/MinGW/.Net or other additional libraries.

As far as I understand GCC runs on windows through cygwin, so any app produced by it also needs cygwin1.dll in its presence to run, right ?

Surjit Samra
  • 4,614
  • 1
  • 26
  • 36
rsk82
  • 28,217
  • 50
  • 150
  • 240
  • 1
    possible duplicate of [C compiler for Windows?](http://stackoverflow.com/questions/116368/c-compiler-for-windows) – MK. Dec 18 '11 at 19:47
  • 1
    Don't mix C and C++. They are different languages with different idioms and different ISO standards. The fact that C++ supports a subset of C does not make it C/C++. – Sebastian Mach Dec 19 '11 at 16:27

6 Answers6

4

Your main options are MSVC and mingw.

  • If you want to write C code then avoid MSVC which doesn't have a real C compiler, just a fake wrapper around its C++ compiler. Oh, and the supported dialect is close to C89.
  • If you want to write C++ then MSVC is fine and modern versions have become quite good and reasonably compliant with the standards.
  • If you want to write both C and C++ as per your question then mingw is probably best.

Note that mingw is a native Windows port of the GNU compilers and does not require cygwin. The 32 bit version of mingw is simple to install. If you need to produce 64 bit executables then it's a bit more work to get the 64 bit version of mingw installed. Similarly, if you want the free MS compiler in 64 bit mode you have to do some dirty work to get it installed.

With all of these options you can statically link the runtime to avoid having to deploy a runtime to target machines.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
3

If you install visual studio express ( even if you aren't going to use it ) you will get the tool chain for building C++ code.

If you target native code it will run on any windows..... you might want to look at something like WTL to make doing windows a little easier though.

Also, as per comments, The Platform SDK provides a full compiler toolchain. The other good thing about the SDK is it has a lot of example code for all aspects of the windows API.

Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156
2

The Mingw gcc compiler produces native binaries that only use msvcrt for the C runtime. So that satisfies your requirement. You can go for Visual Studio express but these will require you to ship the version of msvcrt used with your application.

patthoyts
  • 32,320
  • 3
  • 62
  • 93
  • 1
    With static linking, the used functions are embedded in the application binary, and shipping msvcrt is NOT required. – Ben Voigt Dec 18 '11 at 19:58
  • 1
    @Ben I suspect that patthoyts is referring to msvcrt.dll which is a system component and shipped with Windows. – David Heffernan Dec 18 '11 at 20:01
  • @David: I'm addressing the third sentence, which mentions "require you to ship the version of msvcrt" and is inaccurate. – Ben Voigt Dec 18 '11 at 20:08
1

Open Watcom C/C++ may be a good thing for a start, but as far as I understand, it's not up to date with C++ features (most notably in STL it seems) and I'm not even talking about C++11.

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180
1

The Visual C++ compiler (included in Visual C++ Express, Visual Studio, and Windows SDK) can produce binaries that don't require any supporting libraries apart from the OS itself. Use static linking. However, the latest versions no longer support Windows versions prior to XP (there are workarounds, but they aren't clean nor recommended for non-trivial applications, best use of the workarounds is when writing an installer program that tests for prerequisites, so it can give meaningful error messages instead of crash).

The MINGW gcc compiler can produce standalone binaries (reliant only on the OS) too.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
1

I've used a MinGW wrapped version of gcc from equation.com that feels like it's native. Just install that single file and use.

pmg
  • 106,608
  • 13
  • 126
  • 198