The previous use of Visual Stdio is in an IDE environment. These two days of compiling GSL feel particularly inconvenient with the IDE environment, so it took a little time to learn how to use the Visual Stdio C + + compiler and connector at the command line.
I am personally familiar with GCC, so the various usages here have made the GCC analogy, which is also easy to remember.
Compiler CL
The C + + compiler in Visual Stdio is the same, called CL. The following table lists some basic command-line options.
| CL |
GCC |
Description |
| /E |
-E |
Output preprocessing results |
| /fa |
-S |
Output assembly file |
| /za |
-ansi |
Prohibit language extension, these two are not equivalent |
| /dname |
-dname |
Defines a macro that is relative to the #define name that is added to the code |
| /dname=value |
-dname=value |
Defines a macro relative to the #define name value that is added to the code |
| /wall |
-wall |
Turn all warnings on. |
| /od |
-o0 |
Disable optimization |
| /o1 |
-os |
Optimized for the most space-saving goals |
| /o2 |
-o2 |
Optimized for the fastest possible speed |
| /idirecotry |
-idirecotry |
Specify header File Search path |
| /C |
-C |
Generate the target file. obj, not linked |
| /libpath:direcotry |
-ldirecotry |
Specifies the library file search path (msvc/libpath is a link option, before the first link option to specify the/LINK option to tell the compiler driver that subsequent options are passed to the linker) |
| /gr,/gr- |
-frtti,-fno-rtti |
Turn Rtti on or off |
| /link |
-wl |
Link the specified module or pass parameters to the linker |
| /ld |
-shared |
Compiling generated DLL files |
| /ldd |
|
Compiling the DLL file (Debug version) |
| /md |
|
MSVCRT.LIB links with Dynamic multithreaded version run-the-Library |
| /MDd |
|
MSVCRTD.LIB link with Debug version of dynamic multithreaded version runtime |
| /mt |
|
LIBCMT.LIB link to a static multithreaded version run-the-Library |
| /MTd |
|
LIBCMTD.LIB link to the debug version of the static multithreaded version of the runtime library |
In addition to these, there are a lot of command-line options, but for general use, these are enough.
Connector link
Corresponds to the LD in the GCC toolchain.
| Link |
LD |
Description |
| /base:address |
|
Specify the base address of the output file |
| /debug |
|
Output Debug Mode version |
| /def:filename |
|
Specifies the module definition file. Def |
| /defaultlib:library |
|
Specify the default runtime |
| /dll |
–relocateable |
Generate DLL |
| /entry:symbol |
–entry=symbol |
Specifying the program entry |
| /export:symbol |
|
Specify a symbol bit to export symbols |
| /heap |
|
Specify the default heap size |
| /libpath:dir |
|
Specify Link-Time library search Path |
| /map:mapfile |
-map MAPFILE |
Generate Link Map file |
| /nodefaultlib |
|
Disable the default runtime library |
| /out:name |
-O Name |
Specify the output file name as name |
| /stack |
|
Specify the default stack size |
| /subsystem |
|
Specifying subsystems, common options are windows and console |
Generate a static library. Lib
Lib can package a series of obj files into a static library. Lib. You can also combine several. lib into one. Lib. or combine several. obj and. Lib into one. Lib.
For example we have add.obj sub.obj div.lib These three files, we want to make them into a all.lib.
Then you can do this:
Lib Add.obj sub.obj div.lib/out: all.lib
If you want to merge these three files into one all.dll then we need a. def file. Which symbols are given to export.
It looks like this:
LIBRARY all.dllexports Add Sub div
Then execute the link command:
Link/subsystem:windows/dll/def:all.def/out: All.dll add.obj sub.obj div.lib
Visual Stdio C + + compiler, linker common command line (GO)