building error messages

Posted on 2006-05-18
Last Modified: 2008-02-01
In reality this question is about Visual C 6.0 but I couldn't find a more suitable area. When trying to build source code from, I get the following error messages

C:\Project\libcurl\VisualStudio\MyApplication2\MyApplication.cpp(35) : error C2664: 'fread' : cannot convert parameter 4 from 'void *' to 'struct _iobuf *'
        Conversion from 'void*' to pointer to non-'void' requires an explicit cast
C:\Project\libcurl\VisualStudio\MyApplication2\MyApplication.cpp(60) : error C2065: 'open' : undeclared identifier
C:\Project\libcurl\VisualStudio\MyApplication2\MyApplication.cpp(62) : error C2065: 'close' : undeclared identifier

What is the source of these errors?

Source code follows:

#include "stdafx.h"
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>

#include <curl/curl.h>

 * This example shows a HTTP PUT operation. PUTs a file given as a command
 * line argument to the URL also given on the command line.
 * This example also uses its own read callback.
 * Here's an article on how to setup a PUT handler for Apache:

size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
  size_t retcode;

  /* in real-world cases, this would probably get this data differently
     as this fread() stuff is exactly what the library already would do
     by default internally */
  retcode = fread(ptr, size, nmemb, stream);

  fprintf(stderr, "*** We read %d bytes from file\n", retcode);

  return retcode;

int main(int argc, char **argv)
  CURL *curl;
  CURLcode res;
  FILE * hd_src ;
  int hd ;
  struct stat file_info;

  char *file;
  char *url;

  if(argc < 3)
    return 1;

  file= argv[1];
  url = argv[2];

  /* get the file size of the local file */
  hd = open(file, O_RDONLY) ;
  fstat(hd, &file_info);
  close(hd) ;

  /* get a FILE * of the same file, could also be made with
     fdopen() from the previous descriptor, but hey this is just
     an example! */
  hd_src = fopen(file, "rb");

  /* In windows, this will init the winsock stuff */

  /* get a curl handle */
  curl = curl_easy_init();
  if(curl) {
    /* we want to use our own read function */
    curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);

    /* enable uploading */
    curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;

    /* HTTP PUT please */
    curl_easy_setopt(curl, CURLOPT_PUT, TRUE);

    /* specify target URL, and note that this URL should include a file
       name, not only a directory */
    curl_easy_setopt(curl,CURLOPT_URL, url);

    /* now specify which file to upload */
    curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);

    /* and give the size of the upload */
    curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, file_info.st_size);

    /* Now run off and do what you've been told! */
    res = curl_easy_perform(curl);

    /* always cleanup */
  fclose(hd_src); /* close the local file */

  return 0;

Question by:s_federici
    LVL 8

    Accepted Solution

    Some suggestions, not tested:

    I'm not sure how the read_callback is used, but if it sends the FILE* of the file as a void*, you could simply cast it in fread, I think:

    retcode = fread(ptr, size, nmemb, (FILE*) stream);

    That should remove the first error. To remove the next, replacing with:

    hd = _open(file, O_RDONLY) ;
      _fstat(hd, &file_info);
      _close(hd) ;

    might do the trick (underlines).

    Author Comment

    Thanks a lot. It worked immediately. Could you please expand on the reasons why the error raised? A missing library I suppose, but which one?
    LVL 49

    Expert Comment

    If that does not solve it, let me know and I'll download the cURL devkit and see if I can reproduce the problem.

    Author Comment

    Hi Dan,
    khun's suggestion worked well. But I need lot of help about how to effectively use libcurl to upload files to a website behind a firewall that doesn't allow for FTP. I red some documentation about very complicated ways to allow Apache servers to accept http PUT requests. Is there a clean way our there to upload a file to whatever website allowing FTP access, overcoming FTP limitations behind firewalls? Why shouldn't I be allowed to send my files somewhere if I'm allowed to upload them to a site via HTML forms? If you think you can answer my question, I can open a brand new question for you.
    LVL 8

    Expert Comment

    My suggestion is: don't spend time speculating over this if all you want is getting it to work! There are some variations around open/_open/fopen etc. from different compilers and also between different versions of the same compiler. If you get problems, though, you might need to follow up on this.

    For your next question, it would be more appropriate to start a new question. You might also try asking at some of the forums at, seems to be quite many users of this out there! I just took a quick look...

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video discusses moving either the default database or any database to a new volume.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now