Aiy
Aiy

Reputation: 3

Getting error: fatal error: curl/curl.h: No such file or directory #include <curl/curl.h>

I'm trying to use cURL but every time I try to compile a project with it, I get the same error mentioned in the title. I am aware of the dozen or so post about similar issues. However, most of the solutions I've read so far either don't work or I can't seem to find an analog for me as I'm using mingw32 on a windows 10 OS.

I am trying to use the curl-7.76.1-win32-mingw.zip. I got it from the cURL site, and no matter where I try to stick the files, I can't get anything to compile correctly.

Someone, please explain your solution or ideas to me like I'm 5. My brain has melted.

Here is the actual error:

PS C:\Users\Me> g++ -I "C:\Program Files\Curl\curl-7.76.1-win32-mingw\include\curl" -c "D:\Personal\Projects\#####\#####\#####\#####\main.cpp" -o "D:\Personal\Projects\#####\#####\#####\#####/main"
 In file included fromD:\Personal\Projects\#####\#####\#####\#####\main.cpp:4:
D:\Personal\Projects\#####\#####\#####\#####\testapi.hpp:7:10: fatal error: curl/curl.h: No such file or directory
 #include <curl/curl.h>
          ^~~~~~~~~~~~~
compilation terminated.
[Finished in 0.6s]"

Upvotes: 0

Views: 7369

Answers (2)

Luis Colorado
Luis Colorado

Reputation: 12708

You write:

g++ -I "C:\Program Files\Curl\curl-7.76.1-win32-mingw\include\curl"

try better:

g++ -I "C:\Program Files\Curl\curl-7.76.1-win32-mingw\include"

as you have written in the code sample:

#include <curl/curl.h>

or conserve the -I option as it was, and change your #include to:

#include <curl.h>

I sincerely hope this will help.

Upvotes: 0

tansy
tansy

Reputation: 576

Mingw is gcc for windows. Practically everything that applies to gcc applies to mingw.

It's better to use relative paths in your Makefile and with gnu make (which is part of mingw/msys) always use '/' as path separator. If you have to use absolute path like C:\dev\projects\mylib use it this way: C:/dev/projects/mylib.

Back to your curl: curl/curl.h is in C:\path\to\curl-7.76.1-win32-mingw\include\curl\curl.h so you need to add include directory to your gcc command line that points to the right directory, which is C:\path\to\curl-7.76.1-win32-mingw\include because you use "curl/curl.h". If you don't have it (that curl) installed system wide it's also better to use "curl/curl.h" in #include path than <curl/curl.h>.

So all you have to do is add -Ipath/to/curl-7.76.1-win32-mingw/include to your compile line, like:

g++ -O2 -Ipath/to/curl-7.76.1-win32-mingw/include -c -omain.o main.cpp

It can be done automatically in Makefile:

CXX = g++
CFLAGS += -O2
INCLUDES += -Ipath/to/curl-7.76.1-win32-mingw/include

.cpp.o:
    $(CXX) -c $(CXXFLAGS) $(INCLUDES) $*.cpp

Upvotes: 1

Related Questions