Silme94
Silme94

Reputation: 21

curl/curl.h: No such file or directory (Visual Studio 2022 on Windows)

I installed curl with nuget package.

Command that i used to run the command : gcc file.c -L C:/Users/Silme94/Downloads/curl-7.87.0_2-win64-mingw/lib/libcurl.a -lcurl -o file

My code :

#include <stdio.h>
#include <curl/curl.h>

#define DISCORD_WEBHOOK_LINK "link here"
int main(void)
{
    CURL* curl;
    CURLcode res;

    curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_URL, DISCORD_WEBHOOK_LINK);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"content\":\"Hello, Discord!\"}");


        res = curl_easy_perform(curl);

        if (res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                curl_easy_strerror(res));

        curl_easy_cleanup(curl);
    }
    return 0;
}

What gcc show me :

enter image description here

Can anyone help me?

Upvotes: 0

Views: 1194

Answers (1)

JohnFilleau
JohnFilleau

Reputation: 4288

gcc is looking for a file named curl/curl.h, but it doesn't know where to look. You need to use the -I flag to specify Include directories to search. This is very likely -I C:/Users/Silme94/Downloads/curl-7.87.0_2-win64-mingw/include.

You also need to specify additional directories to search for libraries, and you need to specify what libraries to search for. The full command should be

gcc file.c
-L C:/Users/Silme94/Downloads/curl-7.87.0_2-win64-mingw/lib
-I C:/Users/Silme94/Downloads/curl-7.87.0_2-win64-mingw/include
-lcurl
-o file

Upvotes: 1

Related Questions