cURL / Mailing Lists / curl-library / Single Mail

curl-library

libcurl error question

From: <gkghkhjkl_at_aol.com>
Date: Sun, 29 Jun 2014 10:09:39 -0400 (EDT)

I have been trying to get the libcurl library to work with the
following program shown below but I have been getting the following
error:

 ||=== Build: Debug in test3 (compiler: GNU GCC Compiler) ===|
 obj\Debug\main.o||In function `Z8getstockPcS_':|
 undefined reference to `_imp__curl_global_init'|
 undefined reference to `_imp__curl_easy_init'|
 undefined reference to `_imp__curl_easy_setopt'|
 undefined reference to `_imp__curl_easy_setopt'|
 undefined reference to `_imp__curl_easy_setopt'|
 undefined reference to `_imp__curl_easy_setopt'|
 undefined reference to `_imp__curl_easy_setopt'|
 undefined reference to `_imp__curl_easy_perform'|
 undefined reference to `_imp__curl_easy_cleanup'|
 undefined reference to `_imp__curl_global_cleanup'|
  ||=== Build failed: 10 error(s), 0 warning(s) (0 minute(s), 0
second(s)) ===|

  I'm confused as to why this is occurring. I'm using Windows 7 64bit
and Code::Blocks. Under 'build options' 'linker settings' and 'link
libraries' I added all the libraries listed in the lib64 folder namely,
libcrypto.a, libcrypto.dll.a, libcurl.a, libcurldll.a, librtmp.a,
libssh2.a, libssh2dll.a, libssl.a, libssl.dll.a, libz.a, libz.dll.a,
and libzdll.a. Under 'search directories' 'compiler' I included
c:\lib\curl-7.34.0-devel-mingw64\include and under 'search directories'
'linker' I included c:\lib\curl-7.34.0-devel-mingw64\lib64. As far as I
can tell I'm doing everything right. So why isn't this working? Program
shown below.

 #include <stdio.h>
#include <curl/curl.h>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <ctime>
#include <iterator>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <random>
#include <chrono>

using namespace std;

struct FtpFile {
  const char *filename;
  FILE *stream;
};

static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void
*stream)
{
  struct FtpFile *out=(struct FtpFile *)stream;
  if(out && !out->stream) {
    /* open file for writing */
    out->stream=fopen(out->filename, "wb");
    if(!out->stream)
      return -1; /* failure, can't open file to write */
  }
  return fwrite(buffer, size, nmemb, out->stream);
}

void get(char *url3, char *url4);

int main()
{
   
get("http://www.quandl.com/api/v1/datasets/RATEINF/INFLATION_USA.csv?coll
apse=monthly&exclude_headers=true&auth_token=dmpqp2nG2YsJMMn6Hryk","C:\\I
nflationRate.csv");
  return 0;
}

void get(char *url3, char *url4)
{
  CURL *curl;
  CURLcode res;
  struct FtpFile ftpfile={
    url4, /* name to store the file as if succesful */
    NULL
  };

  curl_global_init(CURL_GLOBAL_DEFAULT);

  curl = curl_easy_init();

  if(curl) {
    /*
     * You better replace the URL with one that works!
     */
     curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_easy_setopt(curl, CURLOPT_URL,
                     url3);
     /* Define our callback to get called when there's data to be
written */
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
    /* Set a pointer to our struct to pass to the callback */
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);

    /* Switch on full protocol/debug output */
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

    res = curl_easy_perform(curl);

    /* always cleanup */
    curl_easy_cleanup(curl);

    if(CURLE_OK != res) {
      /* we failed */
      fprintf(stderr, "curl told us %d\n", res);
    }
  }

  if(ftpfile.stream)
    fclose(ftpfile.stream); /* close the local file */

  curl_global_cleanup();
}

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-06-29