build a dynamic library (dll
)
1) with extern "C" __declspec(dllexport)
in the prototype:
cl.exe /LD hello.cpp
2) with a def
file
cl.exe /LD /DEF hello.def hello.cpp
build static library
commands:
1) generate obj
file
cl.exe /c a.cpp b.cpp
2) generate lib
file
lib.exe a.obj b.obj /OUT:mylib.lib
generate import library with lib
lib.exe /DEF:hello.def
link with dynamic library
cl.exe /c main.cpp
link.exe main.obj hello.lib
/MT
and /MD
/MT
multi-threaded (implies static lib)/MD
multi-threaded dynamic (impliesdll
)- No
/ML
anymore.
useful options of dumpbin
/HEADERS
/DEPENDENTS
/EXPORTS
/IMPORTS
/SYMBOLS
for object files
more see: DUMPBIN Options
calling conventions
__cdecl
:
- default.
- Caller clean the stack.
- Underscore(_) is prefixed to names, except exported.
/Gd
__stdcall
:
- used to call Win32 APIs.
- Callee clean the stack.
- Underscore(_) is prefixed to the name.
/Gz
x64
- x64 just uses the __fastcall calling convention and a RISC-based exception-handling model.
- The __fastcall model uses registers for the first four arguments and the stack frame to pass the other parameters.
- /Gd, /Gr, /Gv, /Gz (Calling Convention)
- Overview of x64 Calling Conventions