S
S
Seganapa2012-11-24 14:22:50
Programming
Seganapa, 2012-11-24 14:22:50

Setting up CURL in CodeBlocks MinGW

Good day everyone!
It's been a few days now that I can't connect Curl to CodeBlocks with MinGW (windows 7 32bit).

I tried to do it according to this scheme:
www.lsdeex.ru/archives/3

1. I downloaded Curl from here curl.haxx.se/download.html I
took this one (I don’t know if it’s correct):


2. I unpacked the archive into c:\curl
, here are the contents:


3. I start cmd, go to the folder with the unpacked Curl, execute mingw32-make mingw32
at the end I get:


4. Then following the instructions I get two files in the lib directory - libcurl.a and libcurldll.a I
copy them to C:\Program Files\CodeBlocks \MinGW\lib


and the include/curl folder (which contains curl.h) in C:\Program Files\CodeBlocks\MinGW\lib\include


5. Now I run CodeBlocks
I do:



6. I write a small test code:

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

using namespace std;

static char errorBuffer[CURL_ERROR_SIZE];
static string buffer;
static int writer(char *data, size_t size, size_t nmemb, std::string *buffer)
{
  int result = 0;

  if (buffer != NULL)
  {
    buffer->append(data, size * nmemb);
    result = size * nmemb;
  }

  return result;
}

int main()
{
    char url[] = "http://google.ru";
    cout << "Retrieving " << url << endl;

    CURL *curl;
    CURLcode result;

    curl = curl_easy_init();

    if(!curl)
    {
        cout << "cant init curl. exit";
        return 0;
    }

    curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_HEADER, 1);
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);

    result = curl_easy_perform(curl); // as curl_exec

    curl_easy_cleanup(curl);

    if (result == CURLE_OK)
    {
        cout << buffer << "\n";
        exit(0);
    }else{
        cout << "Error: [" << result << "] - " << errorBuffer;
        exit(-1);
    }
}


7. Here's what I get.:


Please help me solve the problem!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Seganapa, 2012-11-24
@Seganapa

THE QUESTION IS CLOSED! It was necessary to register the path in the global compiler settings

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question