Jump to content

How to fix C++ [Linker error] undefined reference to Download::download?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
thommyy

thommyy

    Newbie

  • Members
  • Pip
  • 4 posts
Hi, i found this code on web to download files from url. When i try to compile it i get this error: " [Linker error] undefined reference to `Download::download(char*, bool, void (*)(unsigned long, unsigned long))'".

any help is appreciated.

Here is code

download.h:


// Header file for downloader.


#ifndef DOWNLOAD_H

#define DOWNLOAD_H

#include <string>

#include <windows.h>

#include <wininet.h>

#include <fstream>


using namespace std;


const int MAX_ERRMSG_SIZE = 80;

const int MAX_FILENAME_SIZE = 512;

const int BUF_SIZE = 10240;             // 10 KB


// Exception class for donwload errors;

class DLExc

    {

        private:

        char err[MAX_ERRMSG_SIZE];

        public:

        DLExc(char *exc)

        {

            if(strlen(exc) < MAX_ERRMSG_SIZE)

            strcpy(err, exc);

        }


	    // Return a pointer to the error message

	    const char *geterr()

	    {

	        return err;

	    }

    };



	// A class for downloading files from the internet

	class Download

	{

	private:

	    static bool ishttp(char *url);

	    static bool httpverOK(HINTERNET hIurl);

	    static bool getfname(char *url, char *fname);

	    static unsigned long openfile(char *url, bool reload, ofstream &fout);

	public:

	    static bool download(char *url, bool reload=false, void (*update)(unsigned long, unsigned long)=NULL);

	};



	#endif



download.cpp:


#include <iostream>

#include <time.h>

#include <cstdlib>

#include "download.h"


using namespace std;


string dat(){

    time_t rawtime;

    struct tm * timeinfo;

    char date[80];

    time ( &rawtime );

    timeinfo=localtime(&rawtime);

    strftime(date,80,"%d%m%y",timeinfo);

    return date;

}


// This function displays the download progress as a percentage

void showprogress(unsigned long total, unsigned long part)

{

    int val = (int) ((double)part / total * 100);

    printf("progress: %i%%\n", val);

}


int main(int argc, char *argv[])

{

    string date=dat();

    string link="http://www.hnb.hr/tecajn/f" + date + ".dat";

    int j=link.length();

    char url[j+1];

    strcpy(url,link.c_str());

    cout << "\nDanasnji datum: " << date << ", a url:" << link << "\n\n";

    //string url[] = linkz;


    bool reload = false;

    if(argc==2 && !strcmp(argv[1], "reload"))

    reload = true;


    printf("Beginning download\n");


    try

    {

        if(Download::download(url, reload, showprogress))

        printf("Download Complete\n");

    }


    catch(DLExc exc)

    {

        printf("%s\n", exc.geterr());

        printf("Download interrupted\n");

    }

    system("PAUSE");

    return EXIT_SUCCESS;

}

Edited by Alyn, 20 October 2011 - 08:21 AM.
added code tag


#2
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
It's because none of the class's functions have actually been defined.
Latinamne loqueris?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users