How to build a DLL from the command line in Windows using MSVC How to build a DLL from the command line in Windows using MSVC c c

How to build a DLL from the command line in Windows using MSVC


On the command line use:

cl.exe /LD <files-to-compile>

or, if you prefer the more verbose & explicit version:

cl.exe /D_USRDLL /D_WINDLL <files-to-compile> <files-to-link> /link /DLL /OUT:<desired-dll-name>.dll


Turns out it happens automatically.

If you have exported functions (e.g. /export, __declspec(dllexport), etc) the linker will automatically generate the .lib file (you do of course need /dll on the linker command line).


Simlar to Ebow Halm's answer, but using a .def file for listing the exported functions and newer command line arguments:

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" && cl /O2 /Iall /Iyour /Iincludes /D_USRDLL /D_WINDLL /DOTHER_DEFINES <libs> <source files> /LD /Fe<dll name> /link /DEF:<def name>.def

References: