By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,529 Members | 864 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,529 IT Pros & Developers. It's quick & easy.

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

P: 8
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.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4.  
  5. #include <curl/curl.h>
  6. #include <curl/types.h>
  7. #include <curl/easy.h>
  8.  
  9. static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
  10. {
  11.   int written = fwrite(ptr, size, nmemb, (FILE *)stream);
  12.   return written;
  13. }
  14.  
  15. int main(int argc, char **argv)
  16. {
  17.   CURL *curl_handle;
  18.   static const char *headerfilename = "head.out";
  19.   FILE *headerfile;
  20.   static const char *bodyfilename = "body.out";
  21.   FILE *bodyfile;
  22.  
  23.   curl_global_init(CURL_GLOBAL_ALL);
  24.  
  25.   /* init the curl session */ 
  26.   curl_handle = curl_easy_init();
  27.  
  28.   /* set URL to get */ 
  29.   curl_easy_setopt(curl_handle, CURLOPT_URL, "http://example.com");
  30.  
  31.   /* no progress meter please */ 
  32.   curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
  33.  
  34.   /* send all data to this function  */ 
  35.   curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
  36.  
  37.   /* open the files */ 
  38.   headerfile = fopen(headerfilename,"w");
  39.   if (headerfile == NULL) {
  40.     curl_easy_cleanup(curl_handle);
  41.     return -1;
  42.   }
  43.   bodyfile = fopen(bodyfilename,"w");
  44.   if (bodyfile == NULL) {
  45.     curl_easy_cleanup(curl_handle);
  46.     return -1;
  47.   }
  48.  
  49.   /* we want the headers to this file handle */ 
  50.   curl_easy_setopt(curl_handle,   CURLOPT_WRITEHEADER, headerfile);
  51.  
  52.   /*
  53.    * Notice here that if you want the actual data sent anywhere else but
  54.    * stdout, you should consider using the CURLOPT_WRITEDATA option.  */ 
  55.  
  56.   /* get it! */ 
  57.   curl_easy_perform(curl_handle);
  58.  
  59.   /* close the header file */ 
  60.   fclose(headerfile);
  61.  
  62.   /* cleanup curl stuff */ 
  63.   curl_easy_cleanup(curl_handle);
  64.  
  65.   return 0;
  66. }
  67.  
But every time I try to compile this, it comes and say:
$ gcc cURLtest.c
/tmp/ccsV6nAV.o:curltest.c:(.text+0x60): undefined reference to '_curl_global_init'
/tmp/cssV6nAV.o:curltest.c:(.text+0x65): undefined reference to '_curl_easy_init'
/tmp/cssV6nAV.o:curltest.c:(.text+0x83): undefined reference to '_curl_easy_setopt'
/tmp/cssV6nAV.o:curltest.c:(.text+0x9e): undefined reference to '_curl_easy_setopt'
....
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.
Nov 26 '10 #1

✓ answered by Banfa

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.

Share this Question
Share on Google+
4 Replies


Banfa
Expert Mod 5K+
P: 8,916
curl_global_init sounds like a fairly basic function.

It looks more like you have not included the cURL library when you linked the program.
Nov 26 '10 #2

P: 8
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
Nov 26 '10 #3

Banfa
Expert Mod 5K+
P: 8,916
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.
Nov 26 '10 #4

P: 8
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
Nov 26 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.