473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.

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.

4 4310
Banfa
9,065 Expert Mod 8TB
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
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
9,065 Expert Mod 8TB
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
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

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

Similar topics

4
by: Nariak | last post by:
Dear friends of programming! the script below only works with MSI and Opera but not with Netscape 7.x and Mozilla 1.x! What is wrong? Please help me! Thanks Ralf
3
by: metcarob | last post by:
Hi, I have the following query: (Simplified version for testing) SELECT IIF(MonAM='S','YES','NO') as IsSick FROM tblAbsence This works prfectly in Access, SQL Server won't like it. I have...
2
by: ALI-R | last post by:
I have a config file in my app ,,called app.config.it works fine in debug but when I deploy application it has no effect.Any suggestion?? Thanks for your help. Here is my app.config ?xml...
0
by: ALI-R | last post by:
I have placed an splitter on my form which I got from here: http://www.codeproject.com/cs/miscctrl/collapsiblesplitter.asp?df=100&forumid=12177&select=997398#xx938401xx I have added a cntrol to...
5
by: Ray Alirezaei | last post by:
Hi all When I copy and paste a piece of code from a web page into IDE ,,it is well formatted and instead of "<" or ">" characters "&alt" shows up.why is that ? Thanks for your help in advance....
4
by: Reza | last post by:
checkedListBox1.ClearSelected(),dosn't clear my selections in my checkedboxlist. How can I clear an specific item based on its value ,name or anything else? thanks for your response.
0
by: yousuf | last post by:
I have a dataList that pulls from a database table - Im trying to do the normal Edit, Update, Delete, Cancel - on it. when I put the following inside a user control - .ascx file it dosn't work,...
4
by: JoeC | last post by:
I am writing a game and I read units into a map manager and there they are placed on a grind and if they are in the same space they will fight. I have an attacker vector and defender fector and if...
14
by: Jonas.Holmsten | last post by:
Hello I'm porting some C++ stuff to C and having problem to get it through gcc. Here is a condensed version of the problem: void foo(const int * const * const ptr) {} main()
7
by: LaiLakY | last post by:
Hi Everybody, I have a project and I upload it to the server but it dosn't work. On my local host it is work fine. I try to write simple page just hello world and upload to the server it same...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.