2

I am trying to use the curl module in C++

<curl/curl.h>

and it gave me an error:

fatal error: curl/curl.h: No such file or directory

So clearly it isn't a pre installed module. So how exactly do I install it using my terminal?

I am using Windows.

Striezel
  • 3,693
  • 7
  • 23
  • 37
x3-
  • 19
  • 2
  • 1
    It could be any number of steps that you've missed. Do you have a general understanding of how to `-I`nclude headers and `-l`ink libraries? – Ted Lyngmo Feb 26 '21 at 04:54
  • 1
    Have your tried to follow the instructions on the curl home site? – 273K Feb 26 '21 at 04:55
  • 1
    Check this [link](https://laptrinhx.com/using-the-curl-library-from-c-on-windows-1267959055/) – KarthikNayak98 Feb 26 '21 at 04:57
  • Curl is a C library, not a C++ one. It is open source. You can download it (see [here](https://curl.se/libcurl/)...) and if allowed by your boss/client compile it on your laptop. And modules existing only in [C++20](https://en.cppreference.com/w/cpp/language/modules) but not in [C](https://en.cppreference.com/w/c) – Basile Starynkevitch Feb 26 '21 at 05:49

3 Answers3

1

As far as I know (at this date), curl is available from Windows 10 v1803 console (I tested and indeed it is). The detailed explanations are here. For the use of libcurl on windows 10, I could not really find resources

There is no curl precompiled package on other windows. You need to either build libcurl from the sources as explained from this excellent resource and here. I tested these resources and they work.

If you use Visual Studio, the resources also show how you configure Visual studio to use it in your programs but I you also have this on SO (I found this resource on SO: How do you properly install libcurl for use in visual studio 2017?)

Pat. ANDRIA
  • 2,330
  • 1
  • 13
  • 27
0

I haven't used that API, but I have used C++ APIs with Visual Studio before, assuming that is your IDE. So i was looking at the tutorial suggested above: link

Basically you need to compile either Libcurl or curlcpp given that the API is written in C. The tutorial explains a method for each, but seems to me that the one suggested for Libcurl is easier, given that there's already a Visual Studio solution for it and you only need to do a double click and compile it (this is a guess, I haven't tried).

Then, once you have built the project, you'll get a folder with files, DLLs and LIB files. The tutorial only says to declare those directories in your project:

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;

This mean, you need to open the Properties of your solution (Right click, Properties), and add the folders required to tell Visual Studio that you have header files outside the typical installation folders.

In the Properties page, Under Configuration Properties, you'll see a property called VC++ Include Directories, in the Include Directories option is where you have to add the paths for the curl\include and curlcpp\include to let VS know that you have headers there.

Navigate thru the Properties page and you'll find the option for all of those steps above, The Include Directory and Library Directory are under the VC++ Directories property, and the Additional Library Directory is under the Linker Properties.

0

Question has been answered here in detailed instructions I can't seem to link g++ to my installed libcurl

In summary (Windows)

  1. Download/Extract/store in project directory curl from official website https://curl.se/download.html
  2. Setup environmental path variables to curl/bin folder
  3. In VSCode add includes, libraries to curl folders in tasks.json. In VStudio edit project properties to add includes and libraries to curl folders
  4. Include curl header
  5. Save, compile program and either run executable or from command line use -l linker and -i include flags along with compiler name and executable path to link curl include and libraries at the terminal (Similar to the VS steps.