#Why is c++ telling me a file doesnt exist

33 messages · Page 1 of 1 (latest)

barren lantern
#

im trying to include curl but i keep getting this error

shadow current
#

curl.h is in a directory other than system includes, so try #include "curl/curl.h" for including that header from a location relative to your project. That should work.

(I assume that in your CMakeLists, you have include directories set to include under your project root.)

barren lantern
#

I tried changing it to #include "curl/curl.h" and the error remained the same

In my CMakeLists file I have the line include_directories(include), which I'm assuming is what you were talking about

shadow current
#

Hmm, usually that helps for me. Did you refresh the CMake build?

There is also the possibility that intellisense is wrong, but I'm not certain about that.

hidden umbraBOT
#

@shadow current has reached level 2. GG!

wicked orbit
gusty shadow
#

Please change it to #include "include/curl/curl.h"

hidden umbraBOT
#

@gusty shadow has reached level 1. GG!

barren lantern
barren lantern
hidden umbraBOT
#

@barren lantern has reached level 1. GG!

gusty shadow
#

please check the main.exe exists on the above path

barren lantern
#

it doesn't as I'm unable to build it

#

I think it's something with the cmake extension I used to start the project

bitter oriole
#

If not, what happens when navigate to the build folder and execute cmake --build . manually?

barren lantern
#

yeah i got the error "undefined reference to `__imp_curl_global_cleanup'" in my code

#

ive tried to fix it but im lost

barren lantern
#
#include <iostream>
#include "include/curl/curl.h"
#include <string>
#define CURL_STATICLIB

using namespace std;

string createDiscordJsonPayload(const std::string& content) {
    return "{\"content\": \"" + content + "\"}";
}

void sendRequest(const string& webhookUrl, const string& messageContent) {
    CURL *curl;
    CURLcode res;

    curl_global_init(CURL_GLOBAL_DEFAULT);
    curl = curl_easy_init();

    if (curl) {
        string jsonPayload = createDiscordJsonPayload(messageContent);

        curl_easy_setopt(curl, CURLOPT_URL, webhookUrl.c_str());
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsonPayload.c_str());

        struct curl_slist* headers = nullptr;
        headers = curl_slist_append(headers, "Content-Type: application/json");
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

        res = curl_easy_perform(curl);

        if (res != CURLE_OK) {
            cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << endl;
        } else {
            cout << "POST request sent successfully!" << endl;
        }
        curl_easy_cleanup(curl);
        curl_slist_free_all(headers);
    } else {
        std::cerr << "Failed to initialize cURL handle!" << std::endl;
    }
    curl_global_cleanup();
}

int main() {
    
    std::string webhookUrl = "webhook";
    std::string messageContent = "hi";

    sendRequest(webhookUrl, messageContent);

    return 0;
}
``` This is my code and the errors that I got
sterile dew
#

maybe clean the build

barren lantern
analog nebula
barren lantern
#

cant remember how I tried to clean it but after some further experimenting I have resolved all my issues

#

The problem was with the linking of the curl library

analog nebula
barren lantern
hidden umbraBOT
#

@barren lantern has reached level 2. GG!

sterile dew
barren lantern
#

it was my first time using c++ libraries so i was a bit lost

sterile dew
#

you won't have that issue using msvs