29

I am just starting out in c++ and cannot figure out how to add libraries, in particular libcurl. I tried a bunch of tutorials but most were for 2013/10 or didn't work. Can anyone please explain (Preferably in standard/non technical English) how I can add the library? I have already tried adding it in the include section of the program and in the additional dependencies menu.

Note this is a re-post I asked virtually the same question around 3 days ago to which I received no replies. Not sure if that is because its very easy and I should have figured it out my self, or if it just got buried in a flood of questions, or some other reason. In any case sorry for the re-post.

RootInit
  • 401
  • 1
  • 4
  • 4

1 Answers1

56

Here's how I've got curl to work with Visual Studio 2017 15.9.14:

  1. Download curl zip package from https://curl.haxx.se/download.html (latest verified is: https://curl.haxx.se/download/curl-7.70.0.zip)
  2. Extract downloaded package to a folder of your choice (e.g. C:\curl\)
  3. Open Developer Command Prompt for VS 2017 (see Windows Start menu or %PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools\) and cd to C:\curl\winbuild\
  4. Run nmake /f Makefile.vc mode=static. This will build curl as a static library into C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\
  5. Create a new project in Visual Studio (e.g. a Windows Console Application)
  6. In Project Properties -> VC++ Directories -> Include Directories add C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\include\
  7. In Project Properties -> VC++ Directories -> Library Directories add C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\lib\ there
  8. In Project Properties -> Linker -> Input -> Additional Dependencies add libcurl_a.lib, Ws2_32.lib, Crypt32.lib, Wldap32.lib and Normaliz.lib
  9. Try to build a sample program:
#define CURL_STATICLIB
#include <curl\curl.h>

int main()
{
    CURL *curl;

    curl = curl_easy_init();
    curl_easy_cleanup(curl);

    return 0;
}

Alternatively you can use vcpkg to install curl:

  1. Get latest vcpkg zip file from https://github.com/microsoft/vcpkg/releases (e.g. https://github.com/microsoft/vcpkg/archive/2019.09.zip) and extract it to a folder of your choice (e.g. C:\vcpkg\)
  2. Open Developer Command Prompt for VS 2017 (see Windows Start menu or %PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools\) and cd to C:\vcpkg\
  3. Run bootstrap-vcpkg.bat
  4. Run vcpkg.exe integrate install
  5. Run vcpkg.exe install curl
  6. Create a new C++ project in Visual Studio and you're ready to go - try it with the example above. There's no need to modify project settings.
Marcin Zawiejski
  • 1,123
  • 1
  • 9
  • 23
  • 1
    Yeah this solution actually works perfectly. Cost me 8 hours to find and figure out. I never get CURL on Windows with OpenSSL support compiled. Anyone has a solution for this? – Digital Human Sep 24 '19 at 15:06
  • @DigitalHuman If you are still interested: https://www.youtube.com/watch?v=nrLEIRChf84 and https://www.youtube.com/watch?v=7pF8GjMBcmA – Emil Mocan Nov 15 '19 at 11:45
  • Hi! I am interested in building libcurl as a static lib with https support. I followed the instructions for the first option downloading https://curl.haxx.se/download.html, but there is no such Makefile.vs file, can't run nmake. Would you provide me a libcurl version (maybe an older one) that contained such file? Thanks – notNullGothik Mar 13 '20 at 02:20
  • @notNullGothik download the zip file (the latest one is https://curl.haxx.se/download/curl-7.69.1.zip) and unzip it. Makefile.vs is inside of the winbuild subfolder. – Marcin Zawiejski Mar 13 '20 at 07:40
  • followed all steps, now I get `cannot open source file "curl\curl.h"` – Roberth May 16 '20 at 05:11
  • I followed every step of first method and while I do have libcurl_a.lib i am missing the other lib files such as Ws2_32.lib However i used vcpkg following your instruction and it did work. Thanks – user Jul 16 '20 at 09:59
  • @user Ws2_32.lib, Crypt32.lib, Wldap32.lib and Normaliz.lib are Windows SDK files – Marcin Zawiejski Feb 14 '21 at 11:18
  • 4
    Amazing answer! The alternative way worked for me. I only add that if you want 64-bit version, use `vcpkg install curl:x64-windows` in step 5. – HiFile.app - best file manager Jul 22 '21 at 17:08
  • Also add Properties -> C++ -> Preprocessor -> CURL_STATICLIB – user2881914 Nov 23 '21 at 13:50