How to run Microsoft C/C++/nmake from the command line
As Microsoft has moved to a more GUI oriented interface to its compiler, it has hidden the internals of the the compiler and make utility from the user. However it is often useful to create make files, project files, or solutions files with a text editor, or code generator, and then construct the final dll/executable from the command line. To add command line functionality one must alter several macros in the environment table. To get a listing of the variables search for a file named vsvars32.bat, and open the file in notepad. Because of the way windows is set up, it is difficult to analyze the contents of a bat file. To view vsvars32.bat:
- ctrl esc search "files and folders" vsvars32.bat
- right click, copy
- open my computer, and paste to c:\
- open a dos box, and type "cd c:\" and then type "notepad vsvars32.bat"
Open the environment table editor:
Start
Settings
Control Panel
System
Advanced
Environement Table
Edit the environment table to have the values for PATH, INCLUDE, LIB and LIBPATH, as defined in vsvars32.bat.
Prepend to the PATH variable:
PATH=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;C:\Program Files\Microsoft Visual Studio 8\VC\BIN;C:\Program Files\Microsoft Visual Studio 8\Common7\Tools;C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\bin;C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\bin;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 8\VC\VCPackages;
Create or prepend to the INCLUDE variable:
INCLUDE=C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\INCLUDE;C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE;C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\include;
Create or prepend to the LIB variable:
LIB=C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\LIB;C:\Program Files\Microsoft Visual Studio 8\VC\LIB;C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\lib;
Create or prepend to the LIBPATH variable:
LIBPATH=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\LIB;
Save the new settings, and open a command prompt. When you type "cl" you should be able to see :
C:\>cl
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
You should be able to compile and run the standard hello world program:
#include <stdio.h>
int main() {
printf( "Hello World!\n");
return 0;
}