Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="https://stackoverflow.com/questions/880803/running-small-c-programs-in-visual-studio-without-creating-projects/880861#880861">GMan's idea</a> of having a 'sandbox' project is a good one, as it allows for easily trying out multi-file tests. I call mine "cppTest".</p> <p>However, if you just want to be able to compile whatever C or C++ file you happen to have open, just create a simple "External Tool". Actually, it's not as simple as it probably should be.</p> <p>First, create a batch file that will set up the compiler environment and run the compiler. Something like the following:</p> <pre><code>@rem - runcl.cmd @rem a batch file to drive simple VC9 compiles #rem @echo off set LIBRARIES=kernel32.lib user32.lib advapi32.lib shlwapi.lib oleaut32.lib set WIN32_WINNT=0x0500 call "%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat" echo Visual C/C++ 2008 (VC 9.0) Compile... set CC="%ProgramFiles%\Microsoft Visual Studio 9.0\VC\bin\cl.exe" /Zi /EHsc -D_WIN32_WINNT=%WIN32_WINNT% %1 /link /incremental:no %LIBRARIES% echo %CC% %CC% </code></pre> <p>In the "Tools/External Tools..." dialog, add a new item and fill in the following fields:</p> <ul> <li>Title: <code>&amp;Compile File</code></li> <li>Command: <code>c:\path\to\runcl.cmd</code></li> <li>Arguments: <code>$(ItemPath)</code></li> <li><p>Initial Directory: <code>$(ItemDir)</code></p></li> <li><p>check the "Use Output Window" box</p></li> </ul> <p>Now you can use the "Compile File" item in the Tools menu to compile whatever is the currently open file. You can even double click on the errors in the output window to take you to the lines with errors.</p> <p>There are some limitations with this some of which you can fix by fancying up the batch file or maybe with a Visual Studio macro (I'm not very familiar with VS macros).</p> <ol> <li>if you haven't saved the file, the compile will run against the most recent save. There's no option in the External Tools configuration to force a save.</li> <li>if you run the command and there's not a C or C++ file active, the batch file will fall over</li> <li>there are probably quite a few other areas where the batch file will get confused</li> </ol> <p>The nice thing about a batch file like this is that you can also use it to help integrate the compiler into various editors that let you call external tools, like UltraEdit, Zeus Editor, EditPad Pro, PSPad, Programmer's Notepad, etc. etc.</p> <p>If you like, I've posted a batch file that I use to integrate several compilers into editors like the above. This batch file handles several compilers including various MSVC compilers from version 6 through version 9, Digital Mars, MinGW and Comeau compilers (the compiler to use is selected by an additional parameter). The batch file is pretty convoluted (unfortunately, that's the nature of Windows batch files that have any kind of complexity). But I find it makes running these things from various editors pretty simple. I can quickly hit a few keys that I've assigned to the compilers to compile a single file against 5 different compilers so I can test for compatibility easily.</p> <p>I make no promises about it other than I find it useful for my own purposes - if you do too, great. Otherwise, don't use it...</p> <ul> <li><a href="https://gist.github.com/mburr/3308168" rel="nofollow noreferrer">https://gist.github.com/mburr/3308168</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload