1. Approach
Some topics …
2. Using the Microsoft C/C++ Compiler from the Command Line in Windows
Hint: This content was created by ChatGPT.
The Microsoft compiler cl.exe and linker link.exe can be used
independently, without a Visual Studio project.
Run the commands in a Developer Command Prompt for Visual Studio, which sets the necessary environment variables and paths.
2.1. Compile source files separately
The /c option compiles a source file without linking.
The result is an object file with the extension .obj.
cl /c /Zi /W3 mkSymbLink.c
cl /c /Zi /W3 mkPath.c
Options:
-
/c- compile only, do not link -
/Zi- generate debugging information -
/W3- warning level 3
2.2. Link existing object files
The linker link.exe combines object files and libraries
to produce an executable.
link /OUT:mkSymbLink.exe mkSymbLink.obj mkPath.obj
The /OUT: option specifies the name of the resulting executable.
Windows system libraries can be specified explicitly, for example:
link /OUT:mkSymbLink.exe mkSymbLink.obj mkPath.obj kernel32.lib
The standard Visual Studio linker environment normally supplies the required default libraries automatically.
2.3. Compile and link in one step
Alternatively, cl.exe can compile and link several source files
in one command:
cl /Zi /W3 /Fe:mkSymbLink.exe mkSymbLink.c mkPath.c
2.4. Further useful compiler options
-
/Od- disable optimization (useful for debugging) -
/Fo:name.obj- specify the object-file name -
/Fe:name.exe- specify the executable name
Note: MSVC uses .obj as its object-file extension, whereas GCC
typically uses .o. Both represent compiled object files.