1*6236dae4SAndroid Build Coastguard Worker<!-- 2*6236dae4SAndroid Build Coastguard WorkerCopyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard Worker 4*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 5*6236dae4SAndroid Build Coastguard Worker--> 6*6236dae4SAndroid Build Coastguard Worker 7*6236dae4SAndroid Build Coastguard Worker# Building curl with Visual C++ 8*6236dae4SAndroid Build Coastguard Worker 9*6236dae4SAndroid Build Coastguard Worker This document describes how to compile, build and install curl and libcurl 10*6236dae4SAndroid Build Coastguard Worker from sources using the Visual C++ build tool. To build with VC++, you will of 11*6236dae4SAndroid Build Coastguard Worker course have to first install VC++. The minimum required version of VC is 6 12*6236dae4SAndroid Build Coastguard Worker (part of Visual Studio 6). However using a more recent version is strongly 13*6236dae4SAndroid Build Coastguard Worker recommended. 14*6236dae4SAndroid Build Coastguard Worker 15*6236dae4SAndroid Build Coastguard Worker VC++ is also part of the Windows Platform SDK. You do not have to install the 16*6236dae4SAndroid Build Coastguard Worker full Visual Studio or Visual C++ if all you want is to build curl. 17*6236dae4SAndroid Build Coastguard Worker 18*6236dae4SAndroid Build Coastguard Worker The latest Platform SDK can be downloaded freely from [Windows SDK and 19*6236dae4SAndroid Build Coastguard Worker emulator 20*6236dae4SAndroid Build Coastguard Worker archive](https://developer.microsoft.com/en-us/windows/downloads/sdk-archive) 21*6236dae4SAndroid Build Coastguard Worker 22*6236dae4SAndroid Build Coastguard Worker## Prerequisites 23*6236dae4SAndroid Build Coastguard Worker 24*6236dae4SAndroid Build Coastguard Worker If you wish to support zlib, OpenSSL, c-ares, ssh2, you will have to download 25*6236dae4SAndroid Build Coastguard Worker them separately and copy them to the `deps` directory as shown below: 26*6236dae4SAndroid Build Coastguard Worker 27*6236dae4SAndroid Build Coastguard Worker somedirectory\ 28*6236dae4SAndroid Build Coastguard Worker |_curl-src 29*6236dae4SAndroid Build Coastguard Worker | |_winbuild 30*6236dae4SAndroid Build Coastguard Worker | 31*6236dae4SAndroid Build Coastguard Worker |_deps 32*6236dae4SAndroid Build Coastguard Worker |_ lib 33*6236dae4SAndroid Build Coastguard Worker |_ include 34*6236dae4SAndroid Build Coastguard Worker |_ bin 35*6236dae4SAndroid Build Coastguard Worker 36*6236dae4SAndroid Build Coastguard Worker It is also possible to create the `deps` directory in some other random places 37*6236dae4SAndroid Build Coastguard Worker and tell the `Makefile` its location using the `WITH_DEVEL` option. 38*6236dae4SAndroid Build Coastguard Worker 39*6236dae4SAndroid Build Coastguard Worker## Building straight from git 40*6236dae4SAndroid Build Coastguard Worker 41*6236dae4SAndroid Build Coastguard Worker When you check out code git and build it, as opposed from a released source 42*6236dae4SAndroid Build Coastguard Worker code archive, you need to first run the `buildconf.bat` batch file (present 43*6236dae4SAndroid Build Coastguard Worker in the source code root directory) to set things up. 44*6236dae4SAndroid Build Coastguard Worker 45*6236dae4SAndroid Build Coastguard Worker## Open a command prompt 46*6236dae4SAndroid Build Coastguard Worker 47*6236dae4SAndroid Build Coastguard WorkerOpen a Visual Studio Command prompt: 48*6236dae4SAndroid Build Coastguard Worker 49*6236dae4SAndroid Build Coastguard Worker Using the **'VS [version] [platform] [type] Command Prompt'** menu entry: 50*6236dae4SAndroid Build Coastguard Worker where [version] is the Visual Studio version, [platform] is e.g. x64 and 51*6236dae4SAndroid Build Coastguard Worker [type] Native or Cross platform build. This type of command prompt may not 52*6236dae4SAndroid Build Coastguard Worker exist in all Visual Studio versions. For example, to build a 64-bit curl open 53*6236dae4SAndroid Build Coastguard Worker the x64 Native Tools prompt. 54*6236dae4SAndroid Build Coastguard Worker 55*6236dae4SAndroid Build Coastguard Worker See also: 56*6236dae4SAndroid Build Coastguard Worker 57*6236dae4SAndroid Build Coastguard Worker [How to: Enable a 64-Bit, x64 hosted MSVC toolset on the command line](https://docs.microsoft.com/en-us/cpp/build/how-to-enable-a-64-bit-visual-cpp-toolset-on-the-command-line) 58*6236dae4SAndroid Build Coastguard Worker 59*6236dae4SAndroid Build Coastguard Worker [Set the Path and Environment Variables for Command-Line Builds](https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line) 60*6236dae4SAndroid Build Coastguard Worker 61*6236dae4SAndroid Build Coastguard Worker [Developer Command Prompt for Visual Studio](https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs) 62*6236dae4SAndroid Build Coastguard Worker 63*6236dae4SAndroid Build Coastguard Worker## Build in the console 64*6236dae4SAndroid Build Coastguard Worker 65*6236dae4SAndroid Build Coastguard Worker Once you are in the console, go to the winbuild directory in the Curl 66*6236dae4SAndroid Build Coastguard Worker sources: 67*6236dae4SAndroid Build Coastguard Worker 68*6236dae4SAndroid Build Coastguard Worker cd curl-src\winbuild 69*6236dae4SAndroid Build Coastguard Worker 70*6236dae4SAndroid Build Coastguard Worker Then you can call `nmake /f Makefile.vc` with the desired options (see 71*6236dae4SAndroid Build Coastguard Worker below). The builds will be in the top src directory, `builds\` directory, in 72*6236dae4SAndroid Build Coastguard Worker a directory named using the options given to the nmake call. 73*6236dae4SAndroid Build Coastguard Worker 74*6236dae4SAndroid Build Coastguard Worker nmake /f Makefile.vc mode=<static or dll> <options> 75*6236dae4SAndroid Build Coastguard Worker 76*6236dae4SAndroid Build Coastguard Workerwhere `<options>` is one or many of: 77*6236dae4SAndroid Build Coastguard Worker 78*6236dae4SAndroid Build Coastguard Worker - `VC=<num>` - VC version. 6 or later. 79*6236dae4SAndroid Build Coastguard Worker - `WITH_DEVEL=<path>` - Paths for the development files (SSL, zlib, etc.) 80*6236dae4SAndroid Build Coastguard Worker Defaults to sibling directory: `../deps` 81*6236dae4SAndroid Build Coastguard Worker - `WITH_SSL=<dll/static>` - Enable OpenSSL support, DLL or static 82*6236dae4SAndroid Build Coastguard Worker - `WITH_NGHTTP2=<dll/static>` - Enable HTTP/2 support, DLL or static 83*6236dae4SAndroid Build Coastguard Worker - `WITH_MSH3=<dll/static>` - Enable (experimental) HTTP/3 support, DLL or static 84*6236dae4SAndroid Build Coastguard Worker - `WITH_MBEDTLS=<dll/static>` - Enable mbedTLS support, DLL or static 85*6236dae4SAndroid Build Coastguard Worker - `WITH_WOLFSSL=<dll/static>` - Enable wolfSSL support, DLL or static 86*6236dae4SAndroid Build Coastguard Worker - `WITH_CARES=<dll/static>` - Enable c-ares support, DLL or static 87*6236dae4SAndroid Build Coastguard Worker - `WITH_ZLIB=<dll/static>` - Enable zlib support, DLL or static 88*6236dae4SAndroid Build Coastguard Worker - `WITH_SSH=<dll/static>` - Enable libssh support, DLL or static 89*6236dae4SAndroid Build Coastguard Worker - `WITH_SSH2=<dll/static>` - Enable libssh2 support, DLL or static 90*6236dae4SAndroid Build Coastguard Worker - `WITH_PREFIX=<dir>` - Where to install the build 91*6236dae4SAndroid Build Coastguard Worker - `ENABLE_SSPI=<yes/no>` - Enable SSPI support, defaults to yes 92*6236dae4SAndroid Build Coastguard Worker - `ENABLE_IPV6=<yes/no>` - Enable IPv6, defaults to yes 93*6236dae4SAndroid Build Coastguard Worker - `ENABLE_IDN=<yes or no>` - Enable use of Windows IDN APIs, defaults to yes 94*6236dae4SAndroid Build Coastguard Worker Requires Windows Vista or later 95*6236dae4SAndroid Build Coastguard Worker - `ENABLE_SCHANNEL=<yes/no>` - Enable native Windows SSL support, defaults 96*6236dae4SAndroid Build Coastguard Worker to yes if SSPI and no other SSL library 97*6236dae4SAndroid Build Coastguard Worker - `ENABLE_OPENSSL_AUTO_LOAD_CONFIG=<yes/no>` 98*6236dae4SAndroid Build Coastguard Worker - Enable loading OpenSSL configuration 99*6236dae4SAndroid Build Coastguard Worker automatically, defaults to yes 100*6236dae4SAndroid Build Coastguard Worker - `ENABLE_UNICODE=<yes/no>` - Enable Unicode support, defaults to no 101*6236dae4SAndroid Build Coastguard Worker - `GEN_PDB=<yes/no>` - Generate External Program Database 102*6236dae4SAndroid Build Coastguard Worker (debug symbols for release build) 103*6236dae4SAndroid Build Coastguard Worker - `DEBUG=<yes/no>` - Debug builds 104*6236dae4SAndroid Build Coastguard Worker - `MACHINE=<x86/x64/arm64>` - Target architecture (default is x86) 105*6236dae4SAndroid Build Coastguard Worker - `CARES_PATH=<path>` - Custom path for c-ares 106*6236dae4SAndroid Build Coastguard Worker - `MBEDTLS_PATH=<path>` - Custom path for mbedTLS 107*6236dae4SAndroid Build Coastguard Worker - `WOLFSSL_PATH=<path>` - Custom path for wolfSSL 108*6236dae4SAndroid Build Coastguard Worker - `NGHTTP2_PATH=<path>` - Custom path for nghttp2 109*6236dae4SAndroid Build Coastguard Worker - `MSH3_PATH=<path>` - Custom path for msh3 110*6236dae4SAndroid Build Coastguard Worker - `SSH2_PATH=<path>` - Custom path for libssh2 111*6236dae4SAndroid Build Coastguard Worker - `SSL_PATH=<path>` - Custom path for OpenSSL 112*6236dae4SAndroid Build Coastguard Worker - `ZLIB_PATH=<path>` - Custom path for zlib 113*6236dae4SAndroid Build Coastguard Worker 114*6236dae4SAndroid Build Coastguard Worker## Cleaning a build 115*6236dae4SAndroid Build Coastguard Worker 116*6236dae4SAndroid Build Coastguard Worker For most build configurations you can remove a bad build by using the same 117*6236dae4SAndroid Build Coastguard Worker options with the added keyword "clean". For example: 118*6236dae4SAndroid Build Coastguard Worker 119*6236dae4SAndroid Build Coastguard Worker nmake /f Makefile.vc mode=static clean 120*6236dae4SAndroid Build Coastguard Worker 121*6236dae4SAndroid Build Coastguard Worker Build errors due to switching Visual Studio platform tools or mistakenly 122*6236dae4SAndroid Build Coastguard Worker specifying the wrong machine platform for the tools can usually be solved by 123*6236dae4SAndroid Build Coastguard Worker first cleaning the bad build. 124*6236dae4SAndroid Build Coastguard Worker 125*6236dae4SAndroid Build Coastguard Worker## Static linking of Microsoft's C runtime (CRT): 126*6236dae4SAndroid Build Coastguard Worker 127*6236dae4SAndroid Build Coastguard Worker If you are using mode=static nmake will create and link to the static build 128*6236dae4SAndroid Build Coastguard Worker of libcurl but *not* the static CRT. If you must you can force nmake to link 129*6236dae4SAndroid Build Coastguard Worker in the static CRT by passing `RTLIBCFG=static`. Typically you shouldn't use 130*6236dae4SAndroid Build Coastguard Worker that option, and nmake will default to the DLL CRT. `RTLIBCFG` is rarely used 131*6236dae4SAndroid Build Coastguard Worker and therefore rarely tested. When passing `RTLIBCFG` for a configuration that 132*6236dae4SAndroid Build Coastguard Worker was already built but not with that option, or if the option was specified 133*6236dae4SAndroid Build Coastguard Worker differently, you must destroy the build directory containing the 134*6236dae4SAndroid Build Coastguard Worker configuration so that nmake can build it from scratch. 135*6236dae4SAndroid Build Coastguard Worker 136*6236dae4SAndroid Build Coastguard Worker This option is not recommended unless you have enough development experience 137*6236dae4SAndroid Build Coastguard Worker to know how to match the runtime library for linking (that is, the CRT). If 138*6236dae4SAndroid Build Coastguard Worker `RTLIBCFG=static` then release builds use `/MT` and debug builds use `/MTd`. 139*6236dae4SAndroid Build Coastguard Worker 140*6236dae4SAndroid Build Coastguard Worker## Building your own application with libcurl (Visual Studio example) 141*6236dae4SAndroid Build Coastguard Worker 142*6236dae4SAndroid Build Coastguard Worker When you build curl and libcurl, nmake will show the relative path where the 143*6236dae4SAndroid Build Coastguard Worker output directory is. The output directory is named from the options nmake used 144*6236dae4SAndroid Build Coastguard Worker when building. You may also see temp directories of the same name but with 145*6236dae4SAndroid Build Coastguard Worker suffixes -obj-curl and -obj-lib. 146*6236dae4SAndroid Build Coastguard Worker 147*6236dae4SAndroid Build Coastguard Worker For example let's say you've built curl.exe and libcurl.dll from the Visual 148*6236dae4SAndroid Build Coastguard Worker Studio 2010 x64 Win64 Command Prompt: 149*6236dae4SAndroid Build Coastguard Worker 150*6236dae4SAndroid Build Coastguard Worker nmake /f Makefile.vc mode=dll VC=10 151*6236dae4SAndroid Build Coastguard Worker 152*6236dae4SAndroid Build Coastguard Worker The output directory will have a name similar to 153*6236dae4SAndroid Build Coastguard Worker `..\builds\libcurl-vc10-x64-release-dll-ipv6-sspi-schannel`. 154*6236dae4SAndroid Build Coastguard Worker 155*6236dae4SAndroid Build Coastguard Worker The output directory contains subdirectories bin, lib and include. Those are 156*6236dae4SAndroid Build Coastguard Worker the directories to set in your Visual Studio project. You can either copy the 157*6236dae4SAndroid Build Coastguard Worker output directory to your project or leave it in place. Following the example, 158*6236dae4SAndroid Build Coastguard Worker let's assume you leave it in place and your curl top source directory is 159*6236dae4SAndroid Build Coastguard Worker `C:\curl-7.82.0`. You would set these options for configurations using the 160*6236dae4SAndroid Build Coastguard Worker x64 platform: 161*6236dae4SAndroid Build Coastguard Worker 162*6236dae4SAndroid Build Coastguard Worker~~~ 163*6236dae4SAndroid Build Coastguard Worker - Configuration Properties > Debugging > Environment 164*6236dae4SAndroid Build Coastguard Worker PATH=C:\curl-7.82.0\builds\libcurl-vc10-x64-release-dll-ipv6-sspi-schannel\bin;%PATH% 165*6236dae4SAndroid Build Coastguard Worker 166*6236dae4SAndroid Build Coastguard Worker - C/C++ > General > Additional Include Directories 167*6236dae4SAndroid Build Coastguard Worker C:\curl-7.82.0\builds\libcurl-vc10-x64-release-dll-ipv6-sspi-schannel\include; 168*6236dae4SAndroid Build Coastguard Worker 169*6236dae4SAndroid Build Coastguard Worker - Linker > General > Additional Library Directories 170*6236dae4SAndroid Build Coastguard Worker C:\curl-7.82.0\builds\libcurl-vc10-x64-release-dll-ipv6-sspi-schannel\lib; 171*6236dae4SAndroid Build Coastguard Worker 172*6236dae4SAndroid Build Coastguard Worker - Linker > Input > Additional Dependencies 173*6236dae4SAndroid Build Coastguard Worker libcurl.lib; 174*6236dae4SAndroid Build Coastguard Worker~~~ 175*6236dae4SAndroid Build Coastguard Worker 176*6236dae4SAndroid Build Coastguard Worker For configurations using the x86 platform (aka Win32 platform) you would 177*6236dae4SAndroid Build Coastguard Worker need to make a separate x86 build of libcurl. 178*6236dae4SAndroid Build Coastguard Worker 179*6236dae4SAndroid Build Coastguard Worker If you build libcurl static (`mode=static`) or debug (`DEBUG=yes`) then the 180*6236dae4SAndroid Build Coastguard Worker library name will vary and separate builds may be necessary for separate 181*6236dae4SAndroid Build Coastguard Worker configurations of your project within the same platform. This is discussed in 182*6236dae4SAndroid Build Coastguard Worker the next section. 183*6236dae4SAndroid Build Coastguard Worker 184*6236dae4SAndroid Build Coastguard Worker## Building your own application with a static libcurl 185*6236dae4SAndroid Build Coastguard Worker 186*6236dae4SAndroid Build Coastguard Worker When building an application that uses the static libcurl library on Windows, 187*6236dae4SAndroid Build Coastguard Worker you must define `CURL_STATICLIB`. Otherwise the linker will look for dynamic 188*6236dae4SAndroid Build Coastguard Worker import symbols. 189*6236dae4SAndroid Build Coastguard Worker 190*6236dae4SAndroid Build Coastguard Worker The static library name has an `_a` suffix in the basename and the debug 191*6236dae4SAndroid Build Coastguard Worker library name has a `_debug` suffix in the basename. For example, 192*6236dae4SAndroid Build Coastguard Worker `libcurl_a_debug.lib` is a static debug build of libcurl. 193*6236dae4SAndroid Build Coastguard Worker 194*6236dae4SAndroid Build Coastguard Worker You may need a separate build of libcurl for each VC configuration combination 195*6236dae4SAndroid Build Coastguard Worker (for example: Debug|Win32, Debug|x64, Release|Win32, Release|x64). 196*6236dae4SAndroid Build Coastguard Worker 197*6236dae4SAndroid Build Coastguard Worker You must specify any additional dependencies needed by your build of static 198*6236dae4SAndroid Build Coastguard Worker libcurl (for example: 199*6236dae4SAndroid Build Coastguard Worker `advapi32.lib;crypt32.lib;normaliz.lib;ws2_32.lib;wldap32.lib`). 200*6236dae4SAndroid Build Coastguard Worker 201*6236dae4SAndroid Build Coastguard Worker## Legacy Windows and SSL 202*6236dae4SAndroid Build Coastguard Worker 203*6236dae4SAndroid Build Coastguard Worker When you build curl using the build files in this directory the default SSL 204*6236dae4SAndroid Build Coastguard Worker backend will be Schannel (Windows SSPI), the native SSL library that comes 205*6236dae4SAndroid Build Coastguard Worker with the Windows OS. Schannel in Windows 8 and earlier is not able to connect 206*6236dae4SAndroid Build Coastguard Worker to servers that no longer support the legacy handshakes and algorithms used by 207*6236dae4SAndroid Build Coastguard Worker those versions. If you will be using curl in one of those earlier versions of 208*6236dae4SAndroid Build Coastguard Worker Windows you should choose another SSL backend like OpenSSL. 209