#Why is c++ telling me a file doesnt exist
33 messages · Page 1 of 1 (latest)
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.)
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
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.
@shadow current has reached level 2. GG!
Are you just going to work with webhooks?
Please change it to #include "include/curl/curl.h"
@gusty shadow has reached level 1. GG!
im trying to figure out the basics of http requests in c++ and webhooks were just the first thing that came to mind
that worked, but I have a different error now saying this
@barren lantern has reached level 1. GG!
please check the main.exe exists on the above path
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
Is there a error?
If not, what happens when navigate to the build folder and execute cmake --build . manually?
yeah i got the error "undefined reference to `__imp_curl_global_cleanup'" in my code
ive tried to fix it but im lost
Share your code please
#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
maybe clean the build
tried that and nothing changed
what compiler?
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
you probably added it to your cmakelistst.txt
i changed the command i used to compile it and it worked, i had to include a bunch of other stuff
@barren lantern has reached level 2. GG!
so you forgot to compile with the library?
yeah
it was my first time using c++ libraries so i was a bit lost
you won't have that issue using msvs