# Undefined Reference Problem

• 11-07-2001
esilja
Undefined Reference Problem
I can't seem to find out the problem here. If anyone could help me, that would be great.

Compiler output:
c:\windows\TEMP\ccTo2Afb.o(.text+0x6b):histog~1.cp p: undefined reference to `average_numbers(int *, int)'
c:\windows\TEMP\ccTo2Afb.o(.text+0xd0):histog~1.cp p: undefined reference to `make_frequency(int *, int, int *, int)'
c:\windows\TEMP\ccTo2Afb.o(.text+0xe4):histog~1.cp p: undefined reference to `make_histogram(int *, int)'

Program:

#include <iostream.h>
#include <stdlib.h>
#include <iomanip.h>
#include <fstream.h>

const int MAX_ELMNTS = 100;
const int ANLYS_RNG = 19;

// ===========Open input file===========
// Gets the name of the input file and opens it for input

void open_input_file ( ifstream &in_file );
// =============Get Data============
// Read data from the file into the array. The array may not be completely
// filled. It will use what is there and discard any extra data.

int get_data
( int numbers[], int size, int range );

// ============Print Data=============
// Print the data as a 2-dimensional array.

void print_data
( const int numbers[], int size, int line_size );

// ============Average Numbers===========
// Reckons the average of the numbers in the array.

float average_numbers
( int numbers[], int size);

// ===========Make Frequency==========
// Puts the frequency count into an array.

void make_frequency
( int numbers[], int size, int frequency[], int range );

// ==============Make histogram========
// Prints the histogram based on the frequency counts.

void make_histogram
( int frequency[], int range );

// ===============main==============
int main()
{
// Local Declarations
int size;
int nums[MAX_ELMNTS];
int frequency[ANLYS_RNG + 1];

// Statements
size = get_data( nums, MAX_ELMNTS, ANLYS_RNG );

cout << "The average of the numbers is "
<< average_numbers( nums, size )
<< endl;

print_data( nums, size, 10 );

make_frequency( nums, size, frequency, ANLYS_RNG );
make_histogram( frequency, ANLYS_RNG );

system("PAUSE");
return 0;
}

// ==========Open Input File===============
void open_input_file
( ifstream &in_file )
{ char in_file_name[80];

cout << "Enter the input file name: ";
cin >> in_file_name;

in_file.open(in_file_name);
if (!in_file)
cerr << "Error opening file\a\a\n", exit(100);
}
// ===========Average Numbers=============
float average_numbers
( const int numbers[], int size )
{ float sum = 0.0;
int i;

for (i = 0; i < size; i++ )
sum = float( numbers[i] ) + sum;
if (size != 0)
{ return (sum/float(size)); }
else
{ cout << "No values entered \n";
exit (101);
}
}
// =============Get Data===============
int get_data
( int numbers[], int size, int range )
{
int data_in;
ifstream fs_data;

open_input_file (fs_data);

while (loader < size && (fs_data >> data_in))
{
if (data_in >= 0 && data_in <= range)
else
cout << "Data point " << data_in
<< " invalid. Ignored. \n";
}

if (loader == size && (fs_data >> data_in))
cout << "\nToo much data. Will process what was read. \n";
}
//==============Print Data===============
void print_data
( const int numbers[], int size, int line_size )
{
int i;
int num_printed = 0;

cout << endl << endl;

for (i = 0; i < size; i++)
{
num_printed++;
cout << setw(4) << numbers[i];
if (num_printed >= line_size)
{
cout << endl;
num_printed = 0;
}
}
cout << endl << endl;
return;
}
//==============Make Frequency==========
void make_frequency
( const int numbers[], int size, int frequency[], int range )
{
int i;

for (i = 0; i <= range; i++)
frequency[i] = 0;
for (i = 0; i <= size; i++)
frequency[numbers[i]] = frequency[numbers[i]] + 1;

return;
}
//=============Make Histogram============
void make_histogram
( const int frequency[], int range )
{
int i;
int j;

for (i = 0; i <= range; i++)
{
cout << setw(3) << i << setw(3) << frequency[i];
for (j = 1; j <= frequency[i]; j++)
cout << "*";
cout << endl;
}
return;
}
• 11-08-2001
zen
It's because the parameter types in your declarations don't match the parameter types in your definitions, so the compiler is looking for the definitions but can't find them.

'const int numbers[]' is not the same as 'int numbers[]'.