Undefined reference to function

Hey all,

I'm sure this is a super simple question but I just can't seem to find the right answer for me. The situation is this, I have a function call, that is supposed to call a function from a declared header file. That header file, looks to a .cpp file for the function. Now, every time I try to run I get "undefined reference to 'histogram(*various arguments*). The code follows, if someone can point out where I've gone wrong it would be a great help. Also, I've tinkered around and I want to say that it doesn't even recognize the header file, I've commented it out and still get the same errors when trying to run.

main.cpp
------------------------------------------------------------------------------

#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include "histogram.h"

using namespace std;

void histogram(const int MaxPages, istream& input, ostream& output);

int main (int argc, char** argv)
{
...

histogram (MaxPages, in, out);
...
}


histogram.h
--------------------------------------------------------------------------
#ifndef HISTOGRAM_H
#define HISTOGRAM_H

#include <iostream>

void histogram(const int MaxPages, std::istream& input, std::ostream& output);

#endif


histogram.cpp
---------------------------------------------------------------------------
#include "histogram.h"
#include "arrayUtils.h"
#include <string>

using namespace std;

void histogram(const int MaxPages, istream& input, ostream& output)
{
...various code blurds
}


END
hi,

I might be wrong but the undefined reference could mean that your histogram.cpp file
is either not been compiled and/or linked into your program.

Not knowing how you compile its hard to say.

Hope this was helpful
Shredded


Could you share with us the entire code?
I'm confused... why do you have your function prototype in both main.cpp and histogram.h?
void histogram(const int MaxPages, istream& input, ostream& output);
Topic archived. No new replies allowed.