How To Set-Up libcurl on Visual Studio 2019

Even though a Windows lover, I should say that working with C++ projects in the Windows environment is not always a pleasant experience. This is mostly due to the challenge of setting up the environment. And sometimes, it is fairly a daunting task. Once everything is set-up, everything becomes smooth and life becomes a lot beautiful. But up until that point, it is one of the worst nightmares driving programmers crazy.

Recently, I tried to work with the libcurl library on my Windows machine and with no surprise, got hit with numerous errors mostly from the linker.

After investing an appropriate amount of time, I got it to work. So I thought it would be helpful for others to share the steps I followed to get the libcurl to work on my Windows machine without any of that payment in time.

Launching Visual Studio Developer Powershell

The build process requires the Visual Studio Developer Command Prompt or Developer Powershell.

They can be found under Tools -> Command Line on the Visual Studio 2019 Menubar.

I used Powershell and it worked fine. Command Prompt should also work.

Building libcurl from Source

First, download the latest source from the Github.

To generate the tool_hugehelp.c file, run the following command.

Otherwise, during the build, it will fail with the message -

Then, from the winbuild directory, start the build with the following commands.

The build will start. It will take several minutes to finish. Upon finishing, ${curl-dir}\builds will contain the build files.

Setting-up Project Configuration

1. Create a new /Open an existing C++ project.

2. Open Project Properties.

3. Add ${curl-dir}\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\include to Configuration Properties -> VC++ Directories -> Include Directories.

4. Add ${curl-dir}\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\lib to Configuration Properties -> VC++ Directories -> Library Directories.

5. Add CURL_STATICLIB to Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions.

6. In Configuration Properties -> Linker -> Input -> Additional Dependencies, add these followings lines-

  • ${curl-dir}\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib
  • Ws2_32.lib
  • Wldap32.lib
  • Crypt32.lib
  • Normaliz.lib

Check If Everything is Set-up Correctly

Now you can try if everything is working with the following code-

References

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store