-- Compiling from the Command Line (Visual Studio 9) J.G. Campbell, 2009-09-02 -- This is for people like me who get irritated by the Visual Studio IDE and the megabytes of data it creates when compiling simple files. Not to mention the fact that it is often not obvious where it places the executable files and where resource files (e.g. simple input files to be read by the executable) must be placed with respect to the executable (DEBUG?) directory. 1. From the VS-9 IDE, select Tools/Visual Studio 2008 Command Prompt This will open a CMD-prompt window with appropriate environment settings. There is an alternative way, see item 4. below 2. Connect to the directory where the C++ source files are; for example c:\cpp4jp\progs\ch02 $> cd c:\cpp4jp\progs\ch02 Prompt becomes: $c:\cpp4jp\progs\ch02> 3. Compiling, linking, and executing. 3.1 Compiling a single file: $c:\cpp4jp\progs\ch02> cl /EHsc hello.cpp hello.exe is created 3.2 Executing the executable: $c:\cpp4jp\progs\ch02> hello (or hello.exe) 3.3 Compiling a multiple files (for example Tr5c.cpp and funs.cpp): $c:\cpp4jp\progs\ch02> cl /EHsc Tr5c.cpp funs.cpp Tr5c.exe is created. Execute as in item 3.2. 4. If you want to avoid having to fire up the VS-9 IDE in order to do item 1, then, 4.1 do the following from the command prompt: $c:\cpp4jp\progs\ch02> "%VS90COMNTOOLS%vsvars32.bat" This executes the settings batch file. "%VS90COMNTOOLS%" is a variable which holds the directory path where vsvars32.bat resides. It doesn't matter, but the following tells you where exactly "%VS90COMNTOOLS%" refers to: $c:\cpp4jp\progs\ch02> echo %VS90COMNTOOLS% C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\ Of course, the exact location may be different on your computer. 4.2 If you do this a lot, you may like to copy vsvars32.bat to somewhere handy, for example $> copy "%VS90COMNTOOLS%vsvars32.bat" c:\ (Of course you can do this with point-and-click.) Or create a directory c:\bin and $> copy "%VS90COMNTOOLS%vsvars32.bat" c:\bin Then you can execute vsvars32.bat as follows from any directory: $c:\cpp4jp\progs\ch02> c:\bin\vsvars32.bat and you are ready to go as in item 3. 5. How to create and edit files witout using the VS IDE? I would tend to use Wordpad.exe. To make life easy, use Search to find a copy of wordpad.exe. For example it may be in C:\Program Files\ Windows NT\Accessories Make a copy to c:\bin $> copy "C:\Program Files\ Windows NT\Accessories"\wordpad.exe c:\bin\ This means that you can easily execute Wordpad from any diectory, for example: $c:\cpp4jp\progs\ch02> c:\bin\wordpad -- end --