title: How to build libcurl as static library and use in project?
body: <p>I can´t get libcurl compiled as static library working in a c++ project.
  Building a project which includes curl leads to linker errors.</p>
  
  <p>I downloaded source code for curl from <a href="https://curl.haxx.se/download.html" rel="nofollow noreferrer">https://curl.haxx.se/download.html</a>.
  I tried to build it as static library following instructuions inside curl-7.65.1\winbuild\BUILD.WINDOWS.txt</p>
  
  <ol>
  <li>run C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat (*vcvars32.bat)</li>
  <li>inside Developer Command Prompt for VS17 cd ..\curl-7.65.1\winbuild</li>
  <li>run nmake /f Makefile.vc mode=static VC=12 MACHINE=x86 DEBUG=no (*MACHINE=x64)</li>
  <li>copy curl-7.65.1\builds folder into the project folder of the vs17 project</li>
  <li>added $(projectdir)builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\include into Project/Properties/C++/General/Additional Include Directories (*x64)</li>
  <li>added $(projectdir)builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl/lib into Project/Properties/Linker/General/Additional Library Directories (*x64)</li>
  <li>added libcurl_a.lib into Project/Properties/Linker/Input/Additional Dependencies</li>
  <li>Included all files inside $(projectdir)builds to Project</li>
  </ol>
  
  <p>My Visual Studio compilation settings are Release and x86</p>
  
  <p>(I also tried the whole process with x64 with modifications [marked with *] in the workflow described above. Result was the same kind of Linker Error)</p>
  
  <p>Used the following sample code to test curl:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>    #include &lt;stdio.h&gt;
      #include &lt;iostream&gt;
  
      #define CURL_STATICLIB
      #include "curl/curl.h"
  
      int main(void)
      {
          CURL *curl;
          CURLcode res;
  
          curl = curl_easy_init();
          if (curl) {
              curl_easy_setopt(curl, CURLOPT_URL, "https://google.com");
              /* example.com is redirected, so we tell libcurl to follow redirection */
              curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  
              /* Perform the request, res will get the return code */
              res = curl_easy_perform(curl);
              /* Check for errors */
              if (res != CURLE_OK)
                  fprintf(stderr, "curl_easy_perform() failed: %s\n",
                      curl_easy_strerror(res));
  
              /* always cleanup */
              curl_easy_cleanup(curl);
          }
  
          std::cin.get();
      }
  </code></pre>
  
  <pre><code>1 &gt; ------Build started : Project: demoCurl, Configuration : Release Win32------
  1 &gt; Application.cpp
  1 &gt; nonblock.obj : error LNK2001 : unresolved external symbol __imp__ioctlsocket@12
  1 &gt; nonblock.obj : error LNK2001 : unresolved external symbol __imp__ioctlsocket@12
  1 &gt; sendf.obj : error LNK2001 : unresolved external symbol __imp__WSAGetLastError@0
  1 &gt; telnet.obj : error LNK2001 : unresolved external symbol __imp__WSAGetLastError@0
  1 &gt; tftp.obj : error LNK2001 : unresolved external symbol __imp__WSAGetLastError@0
  1 &gt; schannel.obj : error LNK2001 : unresolved external symbol __imp__WSAGetLastError@0
  1 &gt; asyn - thread.obj : error LNK2001 : unresolved external symbol __imp__WSAGetLastError@0
  1 &gt; connect.obj : error LNK2001 : unresolved external symbol __imp__WSAGetLastError@0
  1 &gt; ftp.obj : error LNK2001 : unresolved external symbol __imp__WSAGetLastError@0
  1 &gt; select.obj : error LNK2001 : unresolved external symbol __imp__WSAGetLastError@0
  1 &gt; connect.obj : error LNK2001 : unresolved external symbol __imp__bind@12
  1 &gt; ftp.obj : error LNK2001 : unresolved external symbol __imp__bind@12
  1 &gt; tftp.obj : error LNK2001 : unresolved external symbol __imp__bind@12
  1 &gt; connect.obj : error LNK2001 : unresolved external symbol __imp__closesocket@4
  1 &gt; connect.obj : error LNK2001 : unresolved external symbol __imp__connect@12
  1 &gt; connect.obj : error LNK2001 : unresolved external symbol __imp__getpeername@12
  1 &gt; connect.obj : error LNK2001 : unresolved external symbol __imp__getsockname@12
  1 &gt; ftp.obj : error LNK2001 : unresolved external symbol __imp__getsockname@12
  1 &gt; connect.obj : error LNK2001 : unresolved external symbol __imp__getsockopt@20
  1 &gt; smb.obj : error LNK2001 : unresolved external symbol __imp__htons@4
  1 &gt; socks_sspi.obj : error LNK2001 : unresolved external symbol __imp__htons@4
  1 &gt; telnet.obj : error LNK2001 : unresolved external symbol __imp__htons@4
  1 &gt; connect.obj : error LNK2001 : unresolved external symbol __imp__htons@4
  1 &gt; curl_addrinfo.obj : error LNK2001 : unresolved external symbol __imp__htons@4
  1 &gt; doh.obj : error LNK2001 : unresolved external symbol __imp__htons@4
  1 &gt; ftp.obj : error LNK2001 : unresolved external symbol __imp__htons@4
  1 &gt; connect.obj : error LNK2001 : unresolved external symbol __imp__ntohs@4
  1 &gt; ftp.obj : error LNK2001 : unresolved external symbol __imp__ntohs@4
  1 &gt; socks_sspi.obj : error LNK2001 : unresolved external symbol __imp__ntohs@4
  1 &gt; connect.obj : error LNK2001 : unresolved external symbol __imp__recv@16
  1 &gt; sendf.obj : error LNK2001 : unresolved external symbol __imp__recv@16
  1 &gt; connect.obj : error LNK2001 : unresolved external symbol __imp__setsockopt@20
  1 &gt; transfer.obj : error LNK2001 : unresolved external symbol __imp__setsockopt@20
  1 &gt; connect.obj : error LNK2001 : unresolved external symbol __imp__socket@12
  1 &gt; hostip6.obj : error LNK2001 : unresolved external symbol __imp__socket@12
  1 &gt; connect.obj : error LNK2001 : unresolved external symbol __imp__WSASetLastError@4
  1 &gt; curl_addrinfo.obj : error LNK2001 : unresolved external symbol __imp__WSASetLastError@4
  1 &gt; select.obj : error LNK2001 : unresolved external symbol __imp__WSASetLastError@4
  1 &gt; connect.obj : error LNK2001 : unresolved external symbol __imp__WSAIoctl@36
  1 &gt; transfer.obj : error LNK2001 : unresolved external symbol __imp__WSAIoctl@36
  1 &gt; curl_addrinfo.obj : error LNK2001 : unresolved external symbol __imp__getaddrinfo@16
  1 &gt; curl_addrinfo.obj : error LNK2001 : unresolved external symbol __imp__freeaddrinfo@4
  1 &gt; curl_gethostname.obj : error LNK2001 : unresolved external symbol __imp__gethostname@8
  1 &gt; curl_ntlm_core.obj : error LNK2001 : unresolved external symbol __imp__CryptAcquireContextA@20
  1 &gt; md5.obj : error LNK2001 : unresolved external symbol __imp__CryptAcquireContextA@20
  1 &gt; schannel.obj : error LNK2001 : unresolved external symbol __imp__CryptAcquireContextA@20
  1 &gt; curl_ntlm_core.obj : error LNK2001 : unresolved external symbol __imp__CryptReleaseContext@8
  1 &gt; md5.obj : error LNK2001 : unresolved external symbol __imp__CryptReleaseContext@8
  1 &gt; schannel.obj : error LNK2001 : unresolved external symbol __imp__CryptReleaseContext@8
  1 &gt; curl_ntlm_core.obj : error LNK2001 : unresolved external symbol __imp__CryptDestroyKey@4
  1 &gt; curl_ntlm_core.obj : error LNK2001 : unresolved external symbol __imp__CryptGetHashParam@20
  1 &gt; md5.obj : error LNK2001 : unresolved external symbol __imp__CryptGetHashParam@20
  1 &gt; schannel.obj : error LNK2001 : unresolved external symbol __imp__CryptGetHashParam@20
  1 &gt; curl_ntlm_core.obj : error LNK2001 : unresolved external symbol __imp__CryptImportKey@24
  1 &gt; curl_ntlm_core.obj : error LNK2001 : unresolved external symbol __imp__CryptEncrypt@28
  1 &gt; curl_ntlm_core.obj : error LNK2001 : unresolved external symbol __imp__CryptCreateHash@20
  1 &gt; md5.obj : error LNK2001 : unresolved external symbol __imp__CryptCreateHash@20
  1 &gt; schannel.obj : error LNK2001 : unresolved external symbol __imp__CryptCreateHash@20
  1 &gt; curl_ntlm_core.obj : error LNK2001 : unresolved external symbol __imp__CryptHashData@16
  1 &gt; md5.obj : error LNK2001 : unresolved external symbol __imp__CryptHashData@16
  1 &gt; schannel.obj : error LNK2001 : unresolved external symbol __imp__CryptHashData@16
  1 &gt; curl_ntlm_core.obj : error LNK2001 : unresolved external symbol __imp__CryptDestroyHash@4
  1 &gt; md5.obj : error LNK2001 : unresolved external symbol __imp__CryptDestroyHash@4
  1 &gt; schannel.obj : error LNK2001 : unresolved external symbol __imp__CryptDestroyHash@4
  1 &gt; ftp.obj : error LNK2001 : unresolved external symbol __imp__accept@12
  1 &gt; ftp.obj : error LNK2001 : unresolved external symbol __imp__listen@8
  1 &gt; idn_win32.obj : error LNK2001 : unresolved external symbol __imp__IdnToAscii@20
  1 &gt; idn_win32.obj : error LNK2001 : unresolved external symbol __imp__IdnToUnicode@20
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_init
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_sslinit
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_unbind_s
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_set_option
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_simple_bind_s
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_bind_s
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_search_s
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_msgfree
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_err2string
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_first_entry
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_next_entry
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_first_attribute
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_next_attribute
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_get_values_len
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_value_free_len
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_get_dn
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ldap_memfree
  1 &gt; ldap.obj : error LNK2001 : unresolved external symbol __imp__ber_free
  1 &gt; select.obj : error LNK2001 : unresolved external symbol ___WSAFDIsSet@8
  1 &gt; select.obj : error LNK2001 : unresolved external symbol __imp__select@20
  1 &gt; sendf.obj : error LNK2001 : unresolved external symbol __imp__send@16
  1 &gt; telnet.obj : error LNK2001 : unresolved external symbol __imp__send@16
  1 &gt; system_win32.obj : error LNK2001 : unresolved external symbol __imp__WSAStartup@8
  1 &gt; telnet.obj : error LNK2001 : unresolved external symbol __imp__WSAStartup@8
  1 &gt; system_win32.obj : error LNK2001 : unresolved external symbol __imp__WSACleanup@0
  1 &gt; telnet.obj : error LNK2001 : unresolved external symbol __imp__WSACleanup@0
  1 &gt; tftp.obj : error LNK2001 : unresolved external symbol __imp__recvfrom@24
  1 &gt; tftp.obj : error LNK2001 : unresolved external symbol __imp__sendto@24
  1 &gt; krb5_sspi.obj : error LNK2001 : unresolved external symbol __imp__htonl@4
  1 &gt; krb5_sspi.obj : error LNK2001 : unresolved external symbol __imp__ntohl@4
  1 &gt; schannel.obj : error LNK2001 : unresolved external symbol __imp__CryptGenRandom@12
  1 &gt; schannel.obj : error LNK2001 : unresolved external symbol __imp__CertOpenStore@20
  1 &gt; schannel_verify.obj : error LNK2001 : unresolved external symbol __imp__CertOpenStore@20
  1 &gt; schannel.obj : error LNK2001 : unresolved external symbol __imp__CertCloseStore@8
  1 &gt; schannel_verify.obj : error LNK2001 : unresolved external symbol __imp__CertCloseStore@8
  1 &gt; schannel.obj : error LNK2001 : unresolved external symbol __imp__CertEnumCertificatesInStore@8
  1 &gt; schannel.obj : error LNK2001 : unresolved external symbol __imp__CertFindCertificateInStore@24
  1 &gt; schannel.obj : error LNK2001 : unresolved external symbol __imp__CertFreeCertificateContext@4
  1 &gt; schannel_verify.obj : error LNK2001 : unresolved external symbol __imp__CertFreeCertificateContext@4
  1 &gt; schannel.obj : error LNK2001 : unresolved external symbol __imp__CryptStringToBinaryA@28
  1 &gt; schannel_verify.obj : error LNK2001 : unresolved external symbol __imp__CertAddCertificateContextToStore@16
  1 &gt; schannel_verify.obj : error LNK2001 : unresolved external symbol __imp__CertGetNameStringA@24
  1 &gt; schannel_verify.obj : error LNK2001 : unresolved external symbol __imp__CryptQueryObject@44
  1 &gt; schannel_verify.obj : error LNK2001 : unresolved external symbol __imp__CertCreateCertificateChainEngine@8
  1 &gt; schannel_verify.obj : error LNK2001 : unresolved external symbol __imp__CertFreeCertificateChainEngine@4
  1 &gt; schannel_verify.obj : error LNK2001 : unresolved external symbol __imp__CertGetCertificateChain@32
  1 &gt; schannel_verify.obj : error LNK2001 : unresolved external symbol __imp__CertFreeCertificateChain@4
  1 &gt; C:\...\demoCurl\Release\demoCurl.exe : fatal error LNK1120 : 72 unresolved externals
  1 &gt; Done building project "demoCurl.vcxproj" --FAILED.
  ========== Build: 0 succeeded, 1 failed, 0 up - to - date, 0 skipped ==========
  </code></pre>