113498266Sopenharmony_ci<!-- 213498266Sopenharmony_ciCopyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 313498266Sopenharmony_ci 413498266Sopenharmony_ciSPDX-License-Identifier: curl 513498266Sopenharmony_ci--> 613498266Sopenharmony_ci 713498266Sopenharmony_ci# Building curl with Visual C++ 813498266Sopenharmony_ci 913498266Sopenharmony_ci This document describes how to compile, build and install curl and libcurl 1013498266Sopenharmony_ci from sources using the Visual C++ build tool. To build with VC++, you will of 1113498266Sopenharmony_ci course have to first install VC++. The minimum required version of VC is 6 1213498266Sopenharmony_ci (part of Visual Studio 6). However using a more recent version is strongly 1313498266Sopenharmony_ci recommended. 1413498266Sopenharmony_ci 1513498266Sopenharmony_ci VC++ is also part of the Windows Platform SDK. You do not have to install the 1613498266Sopenharmony_ci full Visual Studio or Visual C++ if all you want is to build curl. 1713498266Sopenharmony_ci 1813498266Sopenharmony_ci The latest Platform SDK can be downloaded freely from [Windows SDK and 1913498266Sopenharmony_ci emulator 2013498266Sopenharmony_ci archive](https://developer.microsoft.com/en-us/windows/downloads/sdk-archive) 2113498266Sopenharmony_ci 2213498266Sopenharmony_ci## Prerequisites 2313498266Sopenharmony_ci 2413498266Sopenharmony_ci If you wish to support zlib, OpenSSL, c-ares, ssh2, you will have to download 2513498266Sopenharmony_ci them separately and copy them to the `deps` directory as shown below: 2613498266Sopenharmony_ci 2713498266Sopenharmony_ci somedirectory\ 2813498266Sopenharmony_ci |_curl-src 2913498266Sopenharmony_ci | |_winbuild 3013498266Sopenharmony_ci | 3113498266Sopenharmony_ci |_deps 3213498266Sopenharmony_ci |_ lib 3313498266Sopenharmony_ci |_ include 3413498266Sopenharmony_ci |_ bin 3513498266Sopenharmony_ci 3613498266Sopenharmony_ci It is also possible to create the `deps` directory in some other random places 3713498266Sopenharmony_ci and tell the `Makefile` its location using the `WITH_DEVEL` option. 3813498266Sopenharmony_ci 3913498266Sopenharmony_ci## Building straight from git 4013498266Sopenharmony_ci 4113498266Sopenharmony_ci When you check out code git and build it, as opposed from a released source 4213498266Sopenharmony_ci code archive, you need to first run the `buildconf.bat` batch file (present 4313498266Sopenharmony_ci in the source code root directory) to set things up. 4413498266Sopenharmony_ci 4513498266Sopenharmony_ci## Open a command prompt 4613498266Sopenharmony_ci 4713498266Sopenharmony_ciOpen a Visual Studio Command prompt: 4813498266Sopenharmony_ci 4913498266Sopenharmony_ci Using the **'Developer Command Prompt for VS [version]'** menu entry: where 5013498266Sopenharmony_ci [version} is the Visual Studio version. The developer prompt at default uses 5113498266Sopenharmony_ci the x86 mode. It is required to call `Vcvarsall.bat` to setup the prompt for 5213498266Sopenharmony_ci the machine type you want. This type of command prompt may not exist in all 5313498266Sopenharmony_ci Visual Studio versions. 5413498266Sopenharmony_ci 5513498266Sopenharmony_ci See also: [Developer Command Prompt for Visual 5613498266Sopenharmony_ci Studio](https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs) 5713498266Sopenharmony_ci and [How to: Enable a 64-Bit, x64 hosted MSVC toolset on the command 5813498266Sopenharmony_ci line](https://docs.microsoft.com/en-us/cpp/build/how-to-enable-a-64-bit-visual-cpp-toolset-on-the-command-line) 5913498266Sopenharmony_ci 6013498266Sopenharmony_ci Using the **'VS [version] [platform] [type] Command Prompt'** menu entry: 6113498266Sopenharmony_ci where [version] is the Visual Studio version, [platform] is e.g. x64 and 6213498266Sopenharmony_ci [type] Native of Cross platform build. This type of command prompt may not 6313498266Sopenharmony_ci exist in all Visual Studio versions. 6413498266Sopenharmony_ci 6513498266Sopenharmony_ci See also: [Set the Path and Environment Variables for Command-Line Builds](https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line) 6613498266Sopenharmony_ci 6713498266Sopenharmony_ci## Build in the console 6813498266Sopenharmony_ci 6913498266Sopenharmony_ci Once you are in the console, go to the winbuild directory in the Curl 7013498266Sopenharmony_ci sources: 7113498266Sopenharmony_ci 7213498266Sopenharmony_ci cd curl-src\winbuild 7313498266Sopenharmony_ci 7413498266Sopenharmony_ci Then you can call `nmake /f Makefile.vc` with the desired options (see 7513498266Sopenharmony_ci below). The builds will be in the top src directory, `builds\` directory, in 7613498266Sopenharmony_ci a directory named using the options given to the nmake call. 7713498266Sopenharmony_ci 7813498266Sopenharmony_ci nmake /f Makefile.vc mode=<static or dll> <options> 7913498266Sopenharmony_ci 8013498266Sopenharmony_ciwhere `<options>` is one or many of: 8113498266Sopenharmony_ci 8213498266Sopenharmony_ci - `VC=<num>` - VC version. 6 or later. 8313498266Sopenharmony_ci - `WITH_DEVEL=<path>` - Paths for the development files (SSL, zlib, etc.) 8413498266Sopenharmony_ci Defaults to sibling directory: `../deps` 8513498266Sopenharmony_ci - `WITH_SSL=<dll/static>` - Enable OpenSSL support, DLL or static 8613498266Sopenharmony_ci - `WITH_NGHTTP2=<dll/static>` - Enable HTTP/2 support, DLL or static 8713498266Sopenharmony_ci - `WITH_MSH3=<dll/static>` - Enable (experimental) HTTP/3 support, DLL or static 8813498266Sopenharmony_ci - `WITH_MBEDTLS=<dll/static>` - Enable mbedTLS support, DLL or static 8913498266Sopenharmony_ci - `WITH_CARES=<dll/static>` - Enable c-ares support, DLL or static 9013498266Sopenharmony_ci - `WITH_ZLIB=<dll/static>` - Enable zlib support, DLL or static 9113498266Sopenharmony_ci - `WITH_SSH=<dll/static>` - Enable libSSH support, DLL or static 9213498266Sopenharmony_ci - `WITH_SSH2=<dll/static>` - Enable libSSH2 support, DLL or static 9313498266Sopenharmony_ci - `WITH_PREFIX=<dir>` - Where to install the build 9413498266Sopenharmony_ci - `ENABLE_SSPI=<yes/no>` - Enable SSPI support, defaults to yes 9513498266Sopenharmony_ci - `ENABLE_IPV6=<yes/no>` - Enable IPv6, defaults to yes 9613498266Sopenharmony_ci - `ENABLE_IDN=<yes or no>` - Enable use of Windows IDN APIs, defaults to yes 9713498266Sopenharmony_ci Requires Windows Vista or later 9813498266Sopenharmony_ci - `ENABLE_SCHANNEL=<yes/no>` - Enable native Windows SSL support, defaults 9913498266Sopenharmony_ci to yes if SSPI and no other SSL library 10013498266Sopenharmony_ci - `ENABLE_OPENSSL_AUTO_LOAD_CONFIG=<yes/no>` 10113498266Sopenharmony_ci - Enable loading OpenSSL configuration 10213498266Sopenharmony_ci automatically, defaults to yes 10313498266Sopenharmony_ci - `ENABLE_UNICODE=<yes/no>` - Enable UNICODE support, defaults to no 10413498266Sopenharmony_ci - `GEN_PDB=<yes/no>` - Generate External Program Database 10513498266Sopenharmony_ci (debug symbols for release build) 10613498266Sopenharmony_ci - `DEBUG=<yes/no>` - Debug builds 10713498266Sopenharmony_ci - `MACHINE=<x86/x64/arm64>` - Target architecture (default is x86) 10813498266Sopenharmony_ci - `CARES_PATH=<path>` - Custom path for c-ares 10913498266Sopenharmony_ci - `MBEDTLS_PATH=<path>` - Custom path for mbedTLS 11013498266Sopenharmony_ci - `NGHTTP2_PATH=<path>` - Custom path for nghttp2 11113498266Sopenharmony_ci - `MSH3_PATH=<path>` - Custom path for msh3 11213498266Sopenharmony_ci - `SSH2_PATH=<path>` - Custom path for libSSH2 11313498266Sopenharmony_ci - `SSL_PATH=<path>` - Custom path for OpenSSL 11413498266Sopenharmony_ci - `ZLIB_PATH=<path>` - Custom path for zlib 11513498266Sopenharmony_ci 11613498266Sopenharmony_ci## Static linking of Microsoft's C runtime (CRT): 11713498266Sopenharmony_ci 11813498266Sopenharmony_ci If you are using mode=static nmake will create and link to the static build 11913498266Sopenharmony_ci of libcurl but *not* the static CRT. If you must you can force nmake to link 12013498266Sopenharmony_ci in the static CRT by passing `RTLIBCFG=static`. Typically you shouldn't use 12113498266Sopenharmony_ci that option, and nmake will default to the DLL CRT. `RTLIBCFG` is rarely used 12213498266Sopenharmony_ci and therefore rarely tested. When passing `RTLIBCFG` for a configuration that 12313498266Sopenharmony_ci was already built but not with that option, or if the option was specified 12413498266Sopenharmony_ci differently, you must destroy the build directory containing the 12513498266Sopenharmony_ci configuration so that nmake can build it from scratch. 12613498266Sopenharmony_ci 12713498266Sopenharmony_ci This option is not recommended unless you have enough development experience 12813498266Sopenharmony_ci to know how to match the runtime library for linking (that is, the CRT). If 12913498266Sopenharmony_ci `RTLIBCFG=static` then release builds use `/MT` and debug builds use `/MTd`. 13013498266Sopenharmony_ci 13113498266Sopenharmony_ci## Building your own application with libcurl (Visual Studio example) 13213498266Sopenharmony_ci 13313498266Sopenharmony_ci When you build curl and libcurl, nmake will show the relative path where the 13413498266Sopenharmony_ci output directory is. The output directory is named from the options nmake used 13513498266Sopenharmony_ci when building. You may also see temp directories of the same name but with 13613498266Sopenharmony_ci suffixes -obj-curl and -obj-lib. 13713498266Sopenharmony_ci 13813498266Sopenharmony_ci For example let's say you've built curl.exe and libcurl.dll from the Visual 13913498266Sopenharmony_ci Studio 2010 x64 Win64 Command Prompt: 14013498266Sopenharmony_ci 14113498266Sopenharmony_ci nmake /f Makefile.vc mode=dll VC=10 14213498266Sopenharmony_ci 14313498266Sopenharmony_ci The output directory will have a name similar to 14413498266Sopenharmony_ci `..\builds\libcurl-vc10-x64-release-dll-ipv6-sspi-schannel`. 14513498266Sopenharmony_ci 14613498266Sopenharmony_ci The output directory contains subdirectories bin, lib and include. Those are 14713498266Sopenharmony_ci the directories to set in your Visual Studio project. You can either copy the 14813498266Sopenharmony_ci output directory to your project or leave it in place. Following the example, 14913498266Sopenharmony_ci let's assume you leave it in place and your curl top source directory is 15013498266Sopenharmony_ci `C:\curl-7.82.0`. You would set these options for configurations using the 15113498266Sopenharmony_ci x64 platform: 15213498266Sopenharmony_ci 15313498266Sopenharmony_ci~~~ 15413498266Sopenharmony_ci - Configuration Properties > Debugging > Environment 15513498266Sopenharmony_ci PATH=C:\curl-7.82.0\builds\libcurl-vc10-x64-release-dll-ipv6-sspi-schannel\bin;%PATH% 15613498266Sopenharmony_ci 15713498266Sopenharmony_ci - C/C++ > General > Additional Include Directories 15813498266Sopenharmony_ci C:\curl-7.82.0\builds\libcurl-vc10-x64-release-dll-ipv6-sspi-schannel\include; 15913498266Sopenharmony_ci 16013498266Sopenharmony_ci - Linker > General > Additional Library Directories 16113498266Sopenharmony_ci C:\curl-7.82.0\builds\libcurl-vc10-x64-release-dll-ipv6-sspi-schannel\lib; 16213498266Sopenharmony_ci 16313498266Sopenharmony_ci - Linker > Input > Additional Dependencies 16413498266Sopenharmony_ci libcurl.lib; 16513498266Sopenharmony_ci~~~ 16613498266Sopenharmony_ci 16713498266Sopenharmony_ci For configurations using the x86 platform (aka Win32 platform) you would 16813498266Sopenharmony_ci need to make a separate x86 build of libcurl. 16913498266Sopenharmony_ci 17013498266Sopenharmony_ci If you build libcurl static (`mode=static`) or debug (`DEBUG=yes`) then the 17113498266Sopenharmony_ci library name will vary and separate builds may be necessary for separate 17213498266Sopenharmony_ci configurations of your project within the same platform. This is discussed in 17313498266Sopenharmony_ci the next section. 17413498266Sopenharmony_ci 17513498266Sopenharmony_ci## Building your own application with a static libcurl 17613498266Sopenharmony_ci 17713498266Sopenharmony_ci When building an application that uses the static libcurl library on Windows, 17813498266Sopenharmony_ci you must define `CURL_STATICLIB`. Otherwise the linker will look for dynamic 17913498266Sopenharmony_ci import symbols. 18013498266Sopenharmony_ci 18113498266Sopenharmony_ci The static library name has an `_a` suffix in the basename and the debug 18213498266Sopenharmony_ci library name has a `_debug` suffix in the basename. For example, 18313498266Sopenharmony_ci `libcurl_a_debug.lib` is a static debug build of libcurl. 18413498266Sopenharmony_ci 18513498266Sopenharmony_ci You may need a separate build of libcurl for each VC configuration combination 18613498266Sopenharmony_ci (for example: Debug|Win32, Debug|x64, Release|Win32, Release|x64). 18713498266Sopenharmony_ci 18813498266Sopenharmony_ci You must specify any additional dependencies needed by your build of static 18913498266Sopenharmony_ci libcurl (for example: 19013498266Sopenharmony_ci `advapi32.lib;crypt32.lib;normaliz.lib;ws2_32.lib;wldap32.lib`). 19113498266Sopenharmony_ci 19213498266Sopenharmony_ci## Legacy Windows and SSL 19313498266Sopenharmony_ci 19413498266Sopenharmony_ci When you build curl using the build files in this directory the default SSL 19513498266Sopenharmony_ci backend will be Schannel (Windows SSPI), the native SSL library that comes 19613498266Sopenharmony_ci with the Windows OS. Schannel in Windows <= XP is not able to connect to 19713498266Sopenharmony_ci servers that no longer support the legacy handshakes and algorithms used by 19813498266Sopenharmony_ci those versions. If you will be using curl in one of those earlier versions of 19913498266Sopenharmony_ci Windows you should choose another SSL backend like OpenSSL. 200