setting up libcurl in visual studio (2013) and sending http(s) requests with c++

I’m a mac user, when it comes to generic libraries I love to

./configure
make
make install

One day a buddy (a fellow Mechanical Engineering guy) comes up with a windows laptop and he needs help with a VC++ win32 project which is supposed to make http calls to rotate a servo (fancy :>). Well one has to save his pride. So after lot of fiddle here’s how I did it on visual studio 2013 (shall work in similar way for others as well).

Clone this repository blackrosezy/build-libcurl-windows and go to the cloned directory and run build.bat. 

This should build the library for any version of visual studio you have automatically. Although the README explicitly says All version of Visual Studio express are unsupportedNow you have built header files, library files and dlls in the third-party directory. It shall look like:

third-party
└───libcurl
    ├───include
    │   └───curl
    │           curl.h
    │           curlbuild.h
    │           curlrules.h
    │           curlver.h
    │           easy.h
    │           mprintf.h
    │           multi.h
    │           stdcheaders.h
    │           typecheck-gcc.h
    │
    └───lib
        ├───dll-debug-x64
        │       libcurl_debug.dll
        │       libcurl_debug.lib
        │       libcurl_debug.pdb
        │
        ├───dll-debug-x86
        │       libcurl_debug.dll
        │       libcurl_debug.lib
        │       libcurl_debug.pdb
        │
        ├───dll-release-x64
        │       libcurl.dll
        │       libcurl.lib
        │       libcurl.pdb
        │
        ├───dll-release-x86
        │       libcurl.dll
        │       libcurl.lib
        │       libcurl.pdb
        │
        ├───static-debug-x64
        │       libcurl_a_debug.lib
        │
        ├───static-debug-x86
        │       libcurl_a_debug.lib
        │
        ├───static-release-x64
        │       libcurl_a.lib
        │
        └───static-release-x86
                libcurl_a.lib

Now it’s time to add this to your VC++ win32 project. Create a new project or go to the existing project and follow these steps:

  1. Go to Project | Project Properties | VC++ Directories | Include Directories |  Add the path to the include directory inside the third-party folder. (./third-party/include).
    Note: do not add /third-party/include/curl as most of time it’s included as curl/curl.h in code.
  2. Next, go to Project | Project Properties | Linker | General | Additional Library Directories |  Add the path to the lib directory. (Where libcurl_debug.dll is located). As my project was for x86 architecture I added  ./third-party/lib/dll-debug-x86
  3. Then, go to Project | Project Properties | Linker | Input | Additional Dependencies | And add libcurl_debug.lib
  4. Now build the project, you can use this test code:

    Note: If it throws error like libcurl_debug.dll is missing, it’s because the compiler is unable to find the dll file.  Copy the libcurl_debug.dll file from /third-party/lib/dll-debud-x86 to the debug directory of your visual studio project and try to build again it should work.

    This should give output as some HTML code.

 

That’s it.

2 thoughts on “setting up libcurl in visual studio (2013) and sending http(s) requests with c++

  1. Ruben Garcia

    As of today, if you try to compile in a 64 bit build, you get a build error saying that x64 and x32 do not match.

    Reply
  2. alex

    i have a error with linker. it returns
    Error 1 error LNK1104: cannot open file ‘libcurl_debug.lib’
    idk why i can resolve this. where is this file?
    thanks

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *