tags:

views:

472

answers:

17

It is very easy on Linux to fire-up vi and write a 100-200 lines of code, compile and see the results: ie. Trying small simple examples of C/C++ code.

On windows however, I like Visual Studio but to use it you have create a new solution then a project which then creates a new folder, generates very large PDB and caching files and a small example of 100-200 LOC becomes a 20Mb large project(?!) after compilation.

So the question is how do you write this kind of small codes on Windows? Possibly Cygwin or Dev-C++ (which is not active since 2004?).

+13  A: 

You can compile from the command line using cl.exe. See the MSDN article How to: Compile a Native C++ Program from the Command Line for detailed instructions.

Greg Hewgill
How about a link to the VS 2008 version of that article instead: http://msdn.microsoft.com/en-us/library/ms235639.aspx
superoptimizer
Thanks. I can't imagine the instructions being very different, because the compiler is still called `cl.exe`.
Greg Hewgill
FWIW, just do 'cl myapp.cpp' and you get myapp.exe. Can't be simpler.
Marcus Lindblom
Note that you get the command line compilers even without Visual Studio, by installing the Windows SDK. That's a good thing for build servers (if you can't afford TFS).
OregonGhost
A: 

I usually edit my code within notepad++ then compile it with gcc under cygwin or msys.

Tryum
+6  A: 

For the simplest examples codepad may be an option.

Pascal Cuoq
+5  A: 

I think there's nothing wrong with firing up Visual Studio for some testing. You can delete the 20MB afterwards ;)

However, you can also just invoke the command line compiler on Windows. Just start a Windows SDK console (or Visual Studio console) and you're there. And you can even use vi (need to install it first, of course).

OregonGhost
A: 

I have used Dev-C++ post 2004, and it still works quite well.

I even used projects coded in Dev-C++ for my practicals that had to run on machines using Linux. Just changed the make files.

Soppus
Dev C++ is very buggy and no longer being developed - I suggest you switch to Code::Blocks at http://www.codeblocks.org.
anon
+1  A: 

I haven't used any of them, but MinGW and lcc-win32 seem to be pretty lightweight, and people seem to like them in news:comp.lang.c. MinGW is a port of GNU Compiler Collection for Windows and is free, lcc-win32 is free for non-commercial use.

Alok
Recommending things you haven't used is not a good idea.
anon
+3  A: 

I always use MinGW (GCC for windows) for such tasks.

Terje Mikal
+7  A: 

When you installed Visual Studio it created an entry in your programs named something like "Visual Studio Command Prompt" (maybe in a group "Visual Studio Tools").

Execute that Command Prompt (it sets up some environment variables needed for the command line compiler) and use cl, the command line compiler.

> cl /?
Copyright (C) Microsoft Corporation.  All rights reserved.

                         C/C++ COMPILER OPTIONS


                              -OPTIMIZATION-

/O1 minimize space                      /O2 maximize speed
/Ob<n> inline expansion (default n=0)   /Od disable optimizations (default)
/Og enable global optimization          /Oi[-] enable intrinsic functions
...


Edit -- copy from another answer :)

Microsoft Documentation: VS2005, VS2008

pmg
A: 

I also use Visual Studio; for quick testing and prototyping, I have a file scratch.c on my desktop, which I just load up and test things out in.

I don't see opening Visual Studio, clicking the new document icon, writing code, pressing F5 then just accepting the defaults for everything as being too much effort :)

The other alternative I have (which I don't use for C, but do for Haskell) is to PuTTY into a Linux box I have access to, and do everything on there.

me_and
YAY for PuTTY :)
pmg
+3  A: 

MinGW is a good solution if you're not using anything Visual Studio specific. If you are, in the start menu with Visual Studio, there should be a script that starts a "commandline" for visual studio.

Also, please keep in mind, even if you aren't going to use Visual Studio, if you use MinGW, you're going to run into issues even with things you might not expect (like...if you decide to try the Apple Bonjour SDK, in which case you're going to get nasty link errors) because GCC and MSVC++ libraries don't always play nice.

Travis
A: 

I have a Test.sln which has a Test.vcproj which has a Test.cpp. The solution has a few handy configurations (for maximum C++ std conformance and others). I just paste code into/from the Test.cpp file and compile it that way.

sbi
+1  A: 

And if you don't have access to your local computer, or you are to lazy to look for command line compiler you can paste your code to on-line compiler. There are several of them on the net you can try one of them here. It's free, no registration needed. It has some flaws but for quick code check it's just fine.

You can also use some other languages, C, C++, D, Haskell, Lua, OCaml, PHP, Perl, Python, Ruby, Scheme, Tcl to be precise.

beermann
+2  A: 

Maybe I'm just a *nix geek, but I went on over to http://consoletelnet.sourceforge.net/gccwin32.html and got gcc for win32. I then headed over to http://unxutils.sourceforge.net/ and go these command line tools. (I renamed their find.exe to gfind.exe to avoid conflict with windows find). I then use gvim for win32 to write code and make/gcc to compile it. Now I only have to learn one environment.

KitsuneYMG
+2  A: 

For small bits of code I want to test, such as code that I'm going to include in an SO answer, I always use the command line. My tools on Windows are:

  • the MSYS tools, particularly their bash shell
  • the vim editor
  • the MinGW GCC compiler (Twilight Dragon branch)
anon
+1  A: 

You can do the exact same thing for Windows -- fire up VI and run the output through gcc.

Either get MingGW/MSys, Cygwin, or native ports of each app (gnu tools, vi)

Just because you're using Windows, doesn't mean you're forced to use Visual Studio.

Pod
+1  A: 

I've got a Visual Studio test project with a main file I just overwrite every time I want to test something new. The couple of MB taken up by the .ncb file really really really doesn't matter. A bigger issues is the need to create a project. But I get around that by reusing an old test project.

jalf
A: 

I use cl.exe and nmake.exe from Visual C++ Express to compile small groups of .c and .cpp files. Rolling your own simple Makefile for nmake.exe is easy.

mmsmatt