Compiling from command line with Microsoft Visual C++
Visual C++ supports the possibility to compile 32 bits programs with no need to use the integrated development environment, simply from the comman line.
For that, first of all we need that a series of system environment variables be suitably defined. More concretely they are the variables %INCLUDE% and %LIB% that define the directories where the include and library files are, as well as it is also recommendable to add the directories where the executable file that we need to compile are to the path.
Luckily, during the initial installation of Visual C++ a BAT file called VCVARS32.bat would have been automatically created defining all these environment variables for us. This BAT file is located at the subdirectory BIN that hangs from the directory where you have installed Visaul C++, that by default would be something similar to:
C:\Program Files\Microsoft Visual Studio\VC98\BINMaybe this file is already being automatically executed whenever our operating system starts up, to know that we can just try this test: from the command line type:
set INCLUDEif the system shows a series of paths separated by commas the file has already been executed. If a message telling that the environment variable has not yet been defined (is not defined) is shown you will have to execute the file VCVARS32.bat manually.
CL option(s) file(s) @command_file /link link_optionswhere the only obligatory parameter is file(s) that shall be a list of the sourcecode files and libraries that we want to compile together. The different file types will be distinguished according to its extension, thus:
c will be considered C language source code files, andif we want to use other extensions for our sourcecode files we will have to precede the name of the file with /Tc for files in C language and with /Tp for files written in C++ language (with no space character between these espefier tags and the file name).
cpp and cxx will be considered C++ language source code files.
The option(s) parameter can go intermingled between the files, or before or after them. They are compiling options, because there are many, mainly different types of optimizations, I'm not going to detail them (consult the compiler help typing CL /HELP for a complete list, or take a llok at the Article Compiler Command-Line Syntax of the Visul C++ Programmer's Guide includes in the MSDN).
The @command_file parameter is used to specify the name of a file that contains other command line options preceded by an at sign (@). CL will insert the content of that file at the point of the command line where you specify its name as if you typed the content of the file.
Finally /link link-options is used to specify options to the linker, that are automatically called by CL if the /c option is not specified. It serves to specify the type of executable file that we want to create, the location of libraries and include files and other linker options like the debugging level. Consult the Visual C++ help for more details.
LC test.cppthat would generate the file test.exe.
|Microsoft and Visual C++ are registered trademarks of Microsoft Corporation|
|©The C++ Resources Network, 2000 - All rights reserved|