views:

590

answers:

8

Hey guys,

I'm just getting started with c++ development and I would like to use emacs to write the code and then compile and run it from within emacs using the visual studio 6 compiler. I have already googled around a bit but just can't seem to find an explanation of how this is done. Any pointers?

Thanks for your help,

joerg

+1  A: 

Visual Studio is an IDE

It uses the cl.exe compiler underneath.

Martin York
+3  A: 

I am not sure if you would consider merely swapping the text editor inside of Visual Studio with Emacs, but here is a sf.net project which does just that.

http://sourceforge.net/projects/visemacs/

John Bellone
+2  A: 

Checkout http://www.kuro5hin.org/story/2003/4/1/21741/10470

mamboking
A: 

We use emacs with GNU make (gmake), which is wrapped with our own gmake wrapper executable and it works very well.

Just set up simple a keybinding to invoke cl.exe on .c/.cpp files that you are compiling to build your .obj files. We have one keybinding for initializing a compile in a folder, which will make all .obj files that are not up to date, but this is purely handled by GNU make.

We also have other keybindings, e.g. for linking the executable and starting it etc.

Magnus Skog
A: 

A bit off topic, but why are you using visual studio 6? The compilers (as well as stripped down IDEs) for the current version of visual studio are available for free from Microsoft.

In either case, you can invoke the compiler from the commandline so it should be as simple as setting up a makefile.

Niki Yoshiuchi
+2  A: 

I have done this as a matter of course over the past few years. There are two ways to do this:

  1. In the older versions of VS (including VS 6.0), there is a button to export the nmake file for the project. I do this on occasion and then use nmake to compile. I have

    (setq compile-command "nmake debug ")

    in my .xemace/init.el for this. You have to add the name of the nmake file, and nmake.exe has to be in your path. (BTW, I modified compilation-error-regexp-alist-alist to help moving through the errors. Let me know if you want this as well.)

  2. Newer versions of VS do not have the button to export the nmake file. For these I call devenv.com. In this case I have

    (setq compile-command "devenv.com /build Debug ")

    in my .xemacs/init.el. You have to add the name of the .sln file. Although I did not do this with VS 6.0, I believe that it may work as well.

Andrew Stein
A: 

If you just want to set up a single file to compile then put this at the top of your file...

// -*- compile-command:"g++ test.cpp -g -lwinmm -o test.exe"; -*-

See my blog post on this

Of course you need to adjust to use CL.EXE and choose the appropriate arguments.

For launching make it's a bit trickier since you have to run make as if you were in the parent source directory, when you are editing a file further down the hierarchy.

The only way I know of to do that is to put this at the top of every file ...

// -*- compile-command:"nmake"; default-directory:"c:/projectroot/"; -*-
justinhj
A: 

As a followup to Andrew Stein's answer, to do a command line build on Visual Studio 6 without using nmake, use the syntax:

msdev wspname.dsw /make "project - Win32 Debug"
Grady Borders