I would like to have my C++ program read a web source using libcurl, but it can not open the file "curl.h".
-
using visual studio? – user3808887 Aug 23 '17 at 03:21
-
4Take a look at https://curl.haxx.se/libcurl/c/libcurl-tutorial.html , especially the "compiling the program" section – racraman Aug 23 '17 at 03:28
2 Answers
Unless you've instructed your compiler to search for headers in a place that the curl library is installed independently, you're probably looking for double quotes, assuming you've included curl source. Otherwise you're going to need to fiddle around with include paths in the project settings.
What is the difference between #include <filename> and #include "filename"?
The difference is in the location where the preprocessor searches for the included file.
For #include "filename" the preprocessor searches in the same directory as the file containing the directive, and then like for #include . This method is normally used to include programmer-defined header files.
For #include < filename > the preprocessor searches in an implementation dependent manner, normally in search directories pre-designated by the compiler/IDE. This method is normally used to include standard library header files.
In short, Add the path of the libcurl's include folder in C/C++ -? General -> Additional include directories. This way the Visual Studio will get to know the location of curl.h
In Detail: Using libcurl involves 2 steps:
- Download and build libcurl on your platform.
- Plug-it in your C\C++ application
Step 1: Download code from https://curl.haxx.se/download.html and unzip the zip file in a folder. I guess you already have done it.
cd curl-src\winbuild
nmake /f Makefile.vc mode=<static or dll> <options>
VC=<6,7,8,9,10,11,12,14> - VC versions
WITH_DEVEL=<path> - Paths for the development files (SSL, zlib, etc.)
Defaults to sibbling directory deps: ../deps
Libraries can be fetched at http://windows.php.net/downloads/php-sdk/deps/
Uncompress them into the deps folder.
WITH_SSL=<dll or static> - Enable OpenSSL support, DLL or static
WITH_MBEDTLS=<dll or static> - Enable mbedTLS support, DLL or static
WITH_CARES=<dll or static> - Enable c-ares support, DLL or static
WITH_ZLIB=<dll or static> - Enable zlib support, DLL or static
WITH_SSH2=<dll or static> - Enable libSSH2 support, DLL or static
ENABLE_SSPI=<yes or no> - Enable SSPI support, defaults to yes
ENABLE_IPV6=<yes or no> - Enable IPv6, defaults to yes
ENABLE_IDN=<yes or no> - Enable use of Windows IDN APIs, defaults to yes
Requires Windows Vista or later, or installation from:
https://www.microsoft.com/downloads/details.aspx?FamilyID=AD6158D7-DDBA-416A-9109-07607425A815
ENABLE_WINSSL=<yes or no> - Enable native Windows SSL support, defaults to yes
GEN_PDB=<yes or no> - Generate Program Database (debug symbols for release build)
DEBUG=<yes or no> - Debug builds
MACHINE=<x86 or x64> - Target architecture (default is x86)
For More info, you can read INSTALL file present in the downloaded zip.
Step 2: Once you have the library built, plug-it in you application as: a) Right Click the VS project in which you want to add the dependency of curl and select properties. b) Add the path of the libcurl's include folder in C/C++ -> General -> Additional include directories. This way the Visual Studio will get to know the location of curl.h c) Add the path of libcurl library in linker -> General -> Additional Library Directories. d) Mention libcurl name in Linker -> input -> Additional Dependencies.
You are good to go ! Note: if you are using dll for curl, then this dll should be present in the same directory in which your .exe for the application is present.

- 2,244
- 6
- 27
- 49

- 1
- 2