first I woud like to say that I saw similar post , and I posted this one on it but was removed... so all is in the title. I understood that it could be a problem at the linker step but I don't know why. Indeed, I linked all the (*.a) files on my Code::Blocks projet and added the different paths of the curl library in Linker options and search directories.
I also tried to manually compil and link but I did not succeed.
g++ -L ..\lib\curl\lib64 -I ..\lib\curl\include -lcurl main.cpp
Another attempt
g++ main.cpp -L ..\lib\curl\lib64 -I ..\lib\curl\include -lcurl -o test.exe
This is the error : " undefined reference to 'curl_easy_init' "
This is my code , maybe the source of troubles is here but I don't think so (tried the static lib too )
#include <iostream>
#define CURL_STATICLIB
#include <curl/curl.h>
#include <curl/easy.h>
#include <string>
#include <fstream>
#include <unistd.h>
#include <windows.h>
#include <Lmcons.h>
using namespace std;
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written = fwrite(ptr, size, nmemb, stream);
return written;}
int main(void)
{
/*ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();*/
CURL *curl;
FILE *fp;
CURLcode res;
char *url = "http://stackoverflow.com";
char outfilename[FILENAME_MAX] = "page.html";
curl = curl_easy_init();
if (curl) {
fp = fopen(outfilename,"wb");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
fclose(fp);
}
return 0;
}