Building libCUrl on Windows with /MT and /MTd
curl and libcurl provide a widely used client-side library for transferring
data using protocols such as HTTP and HTTPS. On Windows, libcurl is commonly built using Microsoft Visual
Studio. One non-trivial aspect of this process is configuring the build to use the static C runtime libraries
(/MT for release and /MTd for debug) instead of the default dynamic runtime
(/MD / /MDd).
This article describes a practical method for building libcurl with static runtime linkage on Windows using
the official curl build system and nmake. The procedure is based on curl version 7.37.0 and
Visual Studio, but the general approach applies to other nearby versions with similar build tooling.
Static runtime builds are commonly required when distributing standalone binaries, integrating libcurl into statically linked applications, or avoiding runtime dependency mismatches across deployment environments.
Why /MT and /MTd Matter
The /MT and /MTd compiler flags instruct Visual C++ to link the C runtime library
statically into the binary. This contrasts with /MD and /MDd, which rely on
external runtime DLLs (such as MSVCR*.dll).
Using a static runtime can simplify deployment by removing external runtime dependencies. However, all linked libraries must be built using compatible runtime settings. Mixing static and dynamic runtimes in the same binary can result in linker errors or subtle runtime issues.
The curl Windows build system supports static runtime builds, but this configuration is not enabled by default and must be explicitly selected.
Build Environment and Prerequisites
The instructions below assume the following:
- Windows development environment
- Microsoft Visual Studio installed (Visual Studio 2010 Command Prompt in this example)
- curl source code version 7.37.0
- Use of
nmakeand the provided Windows makefiles
Administrative privileges are not typically required, but the Visual Studio environment variables must be correctly initialized before running any build commands.
Step-by-Step Build Instructions
-
Download and extract the curl source code to a temporary directory.
Source archive available at: http://curl.haxx.se/ - Open the Visual Studio Command Prompt corresponding to your installed version (for example, “Visual Studio Command Prompt (2010)”).
-
Change directory to the Windows build folder within the extracted curl source tree:
\curl-7.37.0\winbuild -
Set the runtime library configuration to static by entering the following command:
set RTLIBCFG=static
This configures the build system to use/MTand/MTd. -
Build the library using
nmake:
Debug build (uses/MTd):
nmake /f MakeFile.vc mode=static DEBUG=yes
Release build (uses/MT):
nmake /f MakeFile.vc mode=static DEBUG=no
Upon completion, the resulting static libraries will be located in the output directories created by the build system.
Common Considerations
When linking libcurl built with a static runtime into an application, ensure that all other third-party libraries are built with compatible runtime settings. Inconsistent runtime linkage is a common cause of linker warnings and runtime instability on Windows.
If SSL/TLS support or additional protocols are required, corresponding dependencies (such as OpenSSL) must also be built with matching runtime and linkage settings.
FAQ
Why not use the default /MD runtime?
Some deployment environments require fully self-contained binaries without external runtime DLL
dependencies.
Does this apply to newer versions of curl?
The general approach remains valid, though file paths and makefile options may change between versions.
Is this method supported by the official curl build system?
Yes. The RTLIBCFG=static option is part of the Windows build configuration provided with curl.