Why doesn't my cygwin work with the cURL example?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lars Pedersen
    New Member
    • Nov 2010
    • 8

    Why doesn't my cygwin work with the cURL example?

    Hi guys

    Compiler: Cygwin
    OS : Windows 7 (64 bit)
    C-Skills: Basic Understanding

    So... I'm trying to make my cygwin compiler work with the cURL library, but it isn't really working all that well...

    I've tried to completely re-install cygwin, by first removing the folder I stored cygwin in and then install cygwin with the 4 different cURL library's possible.

    I can call functions from cURL in my terminal, and they work fine. But I'm trying to make one of the examples they got run.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
     
    #include <curl/curl.h>
    #include <curl/types.h>
    #include <curl/easy.h>
     
    static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
    {
      int written = fwrite(ptr, size, nmemb, (FILE *)stream);
      return written;
    }
     
    int main(int argc, char **argv)
    {
      CURL *curl_handle;
      static const char *headerfilename = "head.out";
      FILE *headerfile;
      static const char *bodyfilename = "body.out";
      FILE *bodyfile;
     
      curl_global_init(CURL_GLOBAL_ALL);
     
      /* init the curl session */ 
      curl_handle = curl_easy_init();
     
      /* set URL to get */ 
      curl_easy_setopt(curl_handle, CURLOPT_URL, "http://example.com");
     
      /* no progress meter please */ 
      curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
     
      /* send all data to this function  */ 
      curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
     
      /* open the files */ 
      headerfile = fopen(headerfilename,"w");
      if (headerfile == NULL) {
        curl_easy_cleanup(curl_handle);
        return -1;
      }
      bodyfile = fopen(bodyfilename,"w");
      if (bodyfile == NULL) {
        curl_easy_cleanup(curl_handle);
        return -1;
      }
     
      /* we want the headers to this file handle */ 
      curl_easy_setopt(curl_handle,   CURLOPT_WRITEHEADER, headerfile);
     
      /*
       * Notice here that if you want the actual data sent anywhere else but
       * stdout, you should consider using the CURLOPT_WRITEDATA option.  */ 
     
      /* get it! */ 
      curl_easy_perform(curl_handle);
     
      /* close the header file */ 
      fclose(headerfile);
     
      /* cleanup curl stuff */ 
      curl_easy_cleanup(curl_handle);
     
      return 0;
    }
    But every time I try to compile this, it comes and say:
    $ gcc cURLtest.c
    /tmp/ccsV6nAV.o:curl test.c:(.text+0 x60): undefined reference to '_curl_global_i nit'
    /tmp/cssV6nAV.o:curl test.c:(.text+0 x65): undefined reference to '_curl_easy_ini t'
    /tmp/cssV6nAV.o:curl test.c:(.text+0 x83): undefined reference to '_curl_easy_set opt'
    /tmp/cssV6nAV.o:curl test.c:(.text+0 x9e): undefined reference to '_curl_easy_set opt'
    ....
    And so on for every curl specific function.
    collect2: id returned 1 exit status

    Is it because these examples are too new? Maybe some of the functions isn't put into the Cygwin cURL lib?

    And most of all, what do I do to solve this problem? I want to use cURL. In advance thanks for your help.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    curl_global_ini t sounds like a fairly basic function.

    It looks more like you have not included the cURL library when you linked the program.

    Comment

    • Lars Pedersen
      New Member
      • Nov 2010
      • 8

      #3
      Well, as far as I know, these functions is contained within <curl/easy.h> so shouldn't that automaticly include it?

      But just to make sure I didn't get you wrong, this is what I type into my Cygwin:
      gcc cURLtest.c

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        That just includes the header into the compilation, you also need to supply the library to the linker.

        The header just says the function exists the library is where it actually exists.

        You need to add something like -lcurl to you gcc like, however I am not sure of the exact name of the library.

        Comment

        • Lars Pedersen
          New Member
          • Nov 2010
          • 8

          #5
          YAY! I must express my happiness! :D

          You have shown me the light! <3

          Ohh well, to say it with real words. That was the exact problem and the exact code I didn't use :D

          So... gcc cURLtest.c -lcurl fixed everything :D

          Comment

          Working...