You are here:

C++/C++ undefined reference error


Hi Bill,  I am fairly new to C++ and I am writing a program that computes values for the power necessary in an aircraft at various altitudes and speeds.  I am getting an error message that says undefined reference to my output functions that is in a separate module.

Here is the error message:

In function `main':
problem5.cpp:(.text+0x47a): undefined reference to `output(double, double, double, double, double, double, double, double, double, double, double)'
collect2: ld returned 1 exit status

My program is as follows:

#include <iostream>
#include <fstream>
#include <cmath>

#include "output.hpp"
#include "performancecalc.hpp"
#include "aspectratio.hpp"
#include "standardatmosphere.hpp"
#include "clvsalpha.hpp"
#include "velocity.hpp"

using namespace std;

int main()
 double alt, h, b, S, d_sl, T_sl, go, a, R, Y1, y2, x1, x2, P_A, C_Do, W, C_lmax, v, vstall, vmax, rho, a_o, alpha_Lo, alpha_Tconst, e, AR, pi, D, T_R, C_D, LD, alpha, C_L, L, alpha_T, a_new, C_Lold, tol, P_Amax, np, sigma, hnew, vnew, P_Rmax, v_max, E_max, RC_max, P_Amaxnew, P_Rmaxnew, v_maxnew, E_maxnew, RC_maxnew, rho_o; ( "assn5output.m" );
 input( "inputAIRCRAFTSPECS.dat" );
 for ( alt = 0; alt <= 2; alt++ )
     h = alt * 2000;
     calculations( b, S, d_sl, T_sl, go, a, R, h, Y1, y2, x1, x2, P_A, C_Do, W, C_lmax, AR, rho, a_o, vstall, vmax, sigma, rho_o );
     //cout << h << endl;
     for ( v = vstall; v <= vmax; v++ )
    PERFORMANCE( W, rho, v, S, a_o, alpha_Lo, alpha_Tconst, C_Do, e, AR, pi, D, T_R, C_D, LD, alpha, C_L, L, alpha_T, a_new, C_Lold, tol, P_Amax, P_A, np, sigma, P_Rmax );
         output( h, v, P_Amax, P_Rmax, v_max, E_max, RC_max, hnew, vnew, P_Amaxnew, P_Rmaxnew );
 fileout.close ();
 return 0;

//, v_maxnew, E_maxnew, RC_maxnew

This is my input/output module:

#include "output.hpp"

ofstream fileout;

double inputfile[20][1];

void input( const char* inputAIRCRAFTSPECS )
ifstream filein; ( inputAIRCRAFTSPECS );
filein >> inputfile[0][0]
       >> inputfile[1][0]
       >> inputfile[2][0]
       >> inputfile[3][0]
       >> inputfile[4][0]
       >> inputfile[5][0]
       >> inputfile[6][0]
       >> inputfile[7][0]
       >> inputfile[8][0]
       >> inputfile[9][0]
       >> inputfile[10][0]
       >> inputfile[11][0]
       >> inputfile[12][0]
       >> inputfile[13][0]
       >> inputfile[14][0]
       >> inputfile[15][0]
       >> inputfile[16][0]
       >> inputfile[17][0]
       >> inputfile[18][0]
  >> inputfile[19][0];

double W = inputfile[0][0];
double S = inputfile[1][0];
double b = inputfile[2][0];
double e = inputfile[3][0];
double C_Do = inputfile[4][0];
double alpha_Tconst = inputfile[5][0];
double a = inputfile[6][0];
double T_sl = inputfile[7][0];
double d_sl = inputfile[8][0];
double go = inputfile[9][0];
double R = inputfile[10][0];
double x1 = inputfile[11][0];
double Y1 = inputfile[12][0];
double x2 = inputfile[13][0];
double y2 = inputfile[14][0];
double C_lmax = inputfile[15][0];
double pi = inputfile[16][0];
double alpha_Lo = inputfile[17][0];
double P_A = inputfile[18][0];
double np = inputfile[19][0];

double calculations( double b, double S, double d_sl, double T_sl, double go, double a, double R, double h, double Y1, double y2, double x1, double x2, double P_A, double C_Do, double W, double C_lmax, double AR, double rho, double a_o, double vstall, double vmax, double sigma, double rho_o )
 AR = Aspect( b, S );
 rho = dens( d_sl, T_sl, go, a, R, h );
 sigma = sigmafunction( rho_o, d_sl, T_sl, go, a, R, h );
 a_o = slope_a_o( Y1, y2, x1, x2 );
 vstall = VSTALL( W, d_sl, S, C_lmax );
 vmax = VMAX( P_A, C_Do, d_sl, S );
 return 0;

void output( double h, double v, double P_Amax, double P_Rmax, double v_max, double E_max, double RC_max, double hnew, double vnew, double P_Amaxnew, double P_Rmaxnew, double v_maxnew, double E_maxnew, double RC_maxnew )
 hnew = h;
 vnew = v;
 P_Amaxnew = P_Amax;
 P_Rmaxnew = P_Rmax;
 //v_maxnew = v_max;
 //E_maxnew = E_max;
 //RC_maxnew = RC_max;

 fileout << hnew << "   " << vnew << "   " << P_Amaxnew << "   " << P_Rmaxnew <<  endl;
 //fileout << hnew << "   " << vnew << "   " << P_Amaxnew << "   " << P_Rmaxnew << "   " << v_maxnew << "   " << E_maxnew << "   " << RCnew << "   " <<  endl;

And this is my performance calculation module:

#include "performancecalc.hpp"

using namespace std;

double PERFORMANCE( double W, double rho, double v, double S, double a_o, double alpha_Lo, double alpha_Tconst, double C_Do, double e, double AR, double pi, double P_Amax, double P_A, double np, double sigma, double P_Rmax, double& L, double& alpha_T, double& a_new, double& C_Lold, double& tol, double& D, double& T_R, double& C_D, double& LD, double& alpha, double& C_L )
 C_L = W/(.5*rho*(pow(v,2))*S);
 tol = 1;
 while ( tol > 0.00000001)
     C_Lold = C_L;
     a_new = a_o/(1+((57.3*a_o)/(pi*e*AR)));
     alpha = (C_L/a_new) + alpha_Lo;
     alpha_T = alpha + alpha_Tconst;
     C_D = C_Do + (1/(pi*e*AR))*(pow(C_L,2));
     D = C_D*.5*rho*(pow(v,2))*S;
     T_R = D/(cos(alpha_T*(pi/180)));
     L = W - T_R*sin(alpha_T*(pi/180));
     LD = L/D;
     C_L = L/(.5*rho*(pow(v,2))*S);
     tol = fabs (C_L - C_Lold);
     //cout << C_L << endl;
 P_Amax = np*sigma*sigma*P_A;
 P_Rmax = D*v;
 return 0;

There are a few other modules but I am fairly confident in those as they are very small and do minor calculations.

Any help would be greatly appreciated.

Hi Taylor,

I don't see output.hpp so I can't check what problem5.cpp is using, but the function output in output.cpp takes 14 double arguments, while the function call to output in program5.cpp has 11 arguments.  Of course the call and function have to match in return type and number and types of arguments.



All Answers

Answers by Expert:

Ask Experts


Bill A


I can answer questions about C++, programming algorithms, Windows programming in MFC (which is C++). I cannot answer questions about STL (templates) and I have no experience with Linux. I do enjoy reviewing code and critiquing it or finding problems in it. I will also gladly show better algorithms or methods if you want to take advantage of that.


I've developed a commercial embedded C compiler/assembler and IDE with debugger toolset, of which the IDE and debugger are written in C++. I work in the industry writing high tech embedded programs and Windows programs to communicate with the embedded devices.

Book: Embedded Systems Design using the Rabbit 3000 Microprocessor Authored Chapter 10 in its entirety.

BS Computer Engineering

©2016 All rights reserved.