curl is a project containing a command line tool and a library that can be used to transfer data using a variety of protocols, including, of course, HTTP and HTTPS. The library API is written in C, but there are various C++ wrappers on top of it. One of those is curlcpp. In this article, I will show how to build these libraries for Windows with Visual Studio.
Here is an example, using curlcpp, of how to get weather data from https://openweathermap.org.
std::stringstream get_response(std::string_view url)
catch (curl::curl_easy_exception const & error)
auto errors = error.get_traceback();
using namespace std::string_literals;
auto appid = "0c7978..."s;
auto location = "Timisoara"s;
auto url = "https://api.openweathermap.org/data/2.5/weather?q=" + location + "&appid=" + appid;
auto json = get_response(url);
std::cout << json.str() << std::endl;
Here is how you get this working on Windows using Visual Studio 2017. The following instructions are for 32-bit version, but you can do the same for 64-bit.
- Download CURL from https://curl.haxx.se/download.html.
- Unzip and open the solution projects\Windows\VC15\curl-all.sln.
- Build configurations LIB Release - DLL Windows SSPI and LIB Debug - DLL Windows SSPI for the target platform that you need (Win32 or x64)
- Copy the output to build\lib\x86\ (or build\lib\x64\). To have both release and debug builds in the same folder name the debug one libcurld.lib.
- Clone or download CURLCPP from https://github.com/JosephP91/curlcpp.
- Create a subfolder called build in the project’s main folder.
- Execute CMake from the build folder to create a Visual Studio solution. Here is an example that assums curl is in the same folder as curlcpp.
1cmake -G "Visual Studio 15 2017" .. -DCURL_LIBRARY=..\curl\build\lib\x86\libcurld.lib -DCURL_INCLUDE_DIR=..\curl\include
- Open the generated project and build it.
- Copy the output to lib\x86 (where lib is a subfolder in the curlcpp project main folder). To be able to have both Debug and Release builds in the same folder rename the Debug build to curlcppd.lib.
For your project using libcurl and curlcpp:
- Add CURL_STATICLIB to the preprocessor definitions.
- Add curl\include and curlcpp\include to the list of Additional Include Directories. (Make sure you include the correct relative paths.)
- Add curl and curlcpp output folders, curl\build\lib\x86 and curlcpp\lib\x86\, to the Additional Library Directories.
- Add the following static libraries to the list of Additional dependencies: libcurld.lib;curlcppd.lib;Crypt32.lib;ws2_32.lib;winmm.lib;wldap32.lib;
Attached is a demo project with libcurl and curlcpp builds for both 32 and 64-bit platforms.