Blog‎ > ‎

Visual Studio 2013 from within emacs

posted Oct 6, 2014, 12:44 AM by Juan Jose Garcia-Ripoll   [ updated Jan 31, 2015, 2:28 PM ]
If you are like me and use nmake and the command line to build C/C++ programs using Microsoft's tools, here is a trick to do that from within emacs. The following function opens a shell window in emacs that runs a shell with the compiler toolbox for building 64bit applications using the x86 executables that Visual Studio 2013 (express) ships. Changing x86_amd64 to other options selects other toolchains, such as 32 bits (x86), arm (arm), etc.
(defun vs2013-amd-shell ()
  "Run `shell' with VC variables as the shell."
  (interactive)
  (let ((explicit-shell-file-name "cmd"))
    (progn
      (shell "*vc-shell*")
      (let ((b (get-buffer "*vc-shell*")))
	(pop-to-buffer b)
	(end-of-buffer)
	(insert "call \"c:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\vcvarsall.bat\" x86_amd64")
	(execute-kbd-macro "\C-m")))))