Reputation: 31
I'm trying to compile with libcurl on a 32bit windows install. I'm using mingw as a compiler. I downloaded libcurl from https://bintray.com/artifact/download/vszakats/generic/curl-7.58.0-win32-mingw.7z and am using this to compile my project:
g++ -o test.exe -g just_get_output.cpp http_requests.cpp -L C:\curl-7.58.0-win32-mingw\lib -lcurl -lpsapi
All the libcurl code is in http_requests.cpp:
#include <stdio.h>
#define CURL_STATICLIB
#include <curl/curl.h>
// https://kukuruku.co/post/a-cheat-sheet-for-http-libraries-in-c/
int http_post(char* url, char* data)
{
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
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);
}
curl_global_cleanup();
return 0;
}
My main body of code, heavily redacted:
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <windows.h>
#include <tchar.h>
#include <psapi.h>
#include "http_requests.cpp"
int main( void ) {
std::string info = "test";
std::string url = "192.168.30.1:8080";
http_post(url, info)
return 0;
}
The error I'm getting:
Z:\>g++ -o test.exe -g just_get_output.cpp http_requests.cpp -L C:\curl-7.58.0-win32-mingw\lib\libcurl.a -lcurl -lpsapi
In file included from just_get_output.cpp:11:0:
http_requests.cpp:3:23: fatal error: curl/curl.h: No such file or directory
#include <curl/curl.h>
^
compilation terminated.
http_requests.cpp:3:23: fatal error: curl/curl.h: No such file or directory
#include <curl/curl.h>
^
compilation terminated.
What is going on? My precompiled libcurl.a is in the right directory, I'm linking it properly using -L and -l, and I'm not sure what I'm missing.
Upvotes: 0
Views: 1153
Reputation: 385144
As always, you should read the documentation:
Compiling the Program
Your compiler needs to know where the libcurl headers are located. Therefore you must set your compiler's include path to point to the directory where you installed them. The 'curl-config'[3] tool can be used to get this information:
$ curl-config --cflags
I haven't used libcurl but, based on this page, I think what you should be executing is this:
g++ -o test.exe -g \
just_get_output.cpp http_requests.cpp \
`curl-config --cflags` \
`curl-config --libs`
Now the required parameters will be emplaced properly for you.
Upvotes: 1
Reputation: 31
This is a compile error. It's expecting the directory above curl/curl.h to be on the include path.
For anyone else looking, you can use -I (capital I) to link to C:\curl-7.58.0-win32-mingw\include. Thank you @RichardCritten!
Upvotes: 1