Linker Errors undefined reference to 'rand'
Hi guys
Can someone please help me out with this. when I try to compile the program below I get the following errors and I have no idea why.
LINKER ERRORS ----
cpu_cache_instructions.o:/exports/Simulations/opt/MIPS/bin/../lib/gcc/sde/3.4.4/../../../../include/c++/3.4.4/bits/locale_facets.tcc:2445: undefined reference to `std::string::size() const'
cpu_cache_instructions.o:/exports/Simulations/opt/MIPS/bin/../lib/gcc/sde/3.4.4/../../../../include/c++/3.4.4/bits/locale_facets.tcc:2454: undefined reference to `std::string::operator[](unsigned long) const'
cpu_cache_instructions.o:/exports/Simulations/opt/MIPS/bin/../lib/gcc/sde/3.4.4/../../../../include/c++/3.4.4/bits/locale_facets.tcc:2456: undefined reference to `std::string::operator[](unsigned long) const'
cpu_cache_instructions.o:/exports/Simulations/opt/MIPS/bin/../lib/gcc/sde/3.4.4/../../../../include/c++/3.4.4/bits/locale_facets.tcc:2459: undefined reference to `std::string::operator[](unsigned long) const'
cpu_cache_instructions.o: In function `main':
/home/vtwb73/usbdisk/Quik_Silva_Upc_FPII/test_bench/FP_Tests/fpchk_stddev.cpp:22: undefined reference to `rand'
/home/vtwb73/usbdisk/Quik_Silva_Upc_FPII/test_bench/FP_Tests/fpchk_stddev.cpp:32: undefined reference to `rand'
cpu_cache_instructions.o: In function `std_Dev(float*, int, float)':
/home/vtwb73/usbdisk/Quik_Silva_Upc_FPII/test_bench/FP_Tests/fpchk_stddev.cpp:110: undefined reference to `pow'
/home/vtwb73/usbdisk/Quik_Silva_Upc_FPII/test_bench/FP_Tests/fpchk_stddev.cpp:113: undefined reference to `sqrt'
cpu_cache_instructions.o: In function `__static_initialization_and_destruction_0':
/exports/Simulations/opt/MIPS/bin/../lib/gcc/sde/3.4.4/../../../../include/c++/3.4.4/iostream:77: undefined reference to `std::ios_base::Init::Init()'
/exports/Simulations/opt/MIPS/bin/../lib/gcc/sde/3.4.4/../../../../include/c++/3.4.4/iostream:77: undefined reference to `std::ios_base::Init::~Init()'
cpu_cache_instructions.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
C++ CODE
Code:
#include <iostream>
#include <math.h>
#include <cstdlib>
using namespace std;
//Display functions
float calculateMean(float [], int);
float std_Dev(float [], int, float);
//enter main function
int main()
{
//Declare variables
int count, greater = 0, greater_eq = 0, less = 0, less_eq = 0, eq = 0, nt_eq = 0;
float Nums[100], old_STDDev, new_STDDev;
float score, totalScores = 0.0, mean = 0.0, STDDev;
//ask user how many scores user wishes to enter
////cout << "How many scores do you wish to enter? ";
count = rand();
old_STDDev = 0.0;
//for loop statement to enter all the scores from the amount the user wishes to enter
for (int i = 1; i <= 9; i++) {
for (int num = 1; num <= 20; num++)
{
Nums[num] = rand();
//cout << "The Random Number is " << Nums[num] << ": \n";
}
//Function to calculateMean()
mean = calculateMean(Nums, 20);
STDDev = std_Dev(Nums,20,mean);
new_STDDev = STDDev;
if ( new_STDDev > old_STDDev ) {
greater++;
}
if ( new_STDDev < old_STDDev ) {
less++;
}
if ( new_STDDev == old_STDDev ) {
eq++;
}
if ( new_STDDev >= old_STDDev ) {
greater_eq++;
}
if ( new_STDDev <= old_STDDev ) {
less_eq++;
}
if ( new_STDDev != old_STDDev ) {
nt_eq++;
}
old_STDDev = new_STDDev;
}
//cout <<"The Standard Deviation comparason was " << greater_eq <<" "<< less <<" "<< less_eq <<" "<< eq <<" "<< nt_eq <<" \n " << endl;
//return a value
return 0;
}
//calculate Mean function
float calculateMean(float Nums[], int inSize)
{
//Declare variables
float mean, sum, Standard_Deviation;
//Calculate the mean
for ( int i = 0; i < inSize; i++ ){
sum += Nums[i];
}
mean = sum / inSize;
//Display the mean
//cout << "The mean is " << mean << "\n " << endl;
return mean;
}
//calculateStandardDeviation() function
float std_Dev ( float Nums[], int inSize, float avg ){
float sDev, sum2;
for ( int i = 0; i < inSize; i++ ){
sum2 += pow( Nums[i] - avg, 2 );
}
sDev = sqrt( sum2 / ( inSize - 1 ) );
//cout << "The STD Deviation is " << sDev << "\n " << endl;
return sDev;
}