Undefined reference.......

I have a program like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*PROGRAM StatStar
 
    General Description:
    ====================
        StatStar computes a ZAMS model using a number of simplifying assumptions about the physics.  The code
        is not designed to produce precise, research-quality models of ZAMS stars; rather, it is meant to 
        illustrate many of the fundamental physical ideas discussed in
 
            "An Introduction to Modern Astrophysics"
            Bradley W. Carroll and Dale A. Ostlie
            Second Edition, Addison Wesley,   Copyright 2007.
 
        StatStar performs an inward integration of the stellar structure equations, given values for the
        star's mass, luminosity, effective temperature, and composition.
 
        The simplifying assumptions made here include:
            (a) A constant composition throughout (characteristic of a ZAMS star).
            (b) The use of the ideal gas law throughout.
            (c) The gas is assumed to be completely ionized throughout.
            (d) Radiation pressure is incorporated.
            (e) Convection, when present, is taken to be purely adiabatic.
            (f) Opacity is computed by using approximation formulae:
                1.  Bound-free processes via Kramer's formula.
                2.  Free-free processes via Kramer's formula.
                3.  Electron scattering via Thomson formula.
                4.  H- ion via fitting function.
            (g) Surface is assumed to have P = 0, T = 0, rho = 0.
            (h) Outermost (optically thin) zone is assumed to be radiative.
            (i) No attempt is made to satisfy the Eddington approximation by
                adjusting the outside boundary condition.
 
---------------------------------------------------------------------*/

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

#include "User_IO.h"
#include "Boundary_Conditions.h"
#include "Composition.h"
#include "Physics.h"
#include "ODE_Integrator.h"
#include "Stellar_Structure_Equations.h"

using namespace std;

int main()
{
    const double dr_over_r = 0.001;                 //Initial fractional step size
    const double M_fraction_limit = 0.01;           //Mass fraction stop condition
    const double L_fraction_limit = 0.10;           //Luminosity stop condition
    const double r_fraction_limit = 0.02;           //radius stop condition
    const int    maximum_zones = 10000;             //Maximum number of zones allowed
    const int    n_surface = 1;                     //Number of surface boundary zones
    
    bool ok_surface, ok_core, ok_Runge;
    bool adjust_step_size = true;                   //Allow variable step size
    
    const int n = 4;                                //Number of stellar structure equations
    double dfdr0[n];                               //Stellar structure equation evaluations

    double Mm, Lm, rm, Pm, Tm, Xm, Zm;
    double rhom, kappam, taum, epsilonm;
    double rho, kappa, tau, epsilon, gamma, dlnPdlnT;
    char rc_flag;
    int step_size_condition;

Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//---------------------------------------------------------------------

    char all_new = 'Y';                             //Select new model parameter

    while (!(all_new == 'E' || all_new == 'e')){

        int i = 0;                                  //Initialize zone number

        double Msolar, Lsolar, Rsolar, Ms, Ls, Rs, Teff, X, Y, Z;
        Initial_Model(Msolar, Lsolar, Rsolar, Ms, Ls, Rs, Teff, X, Y, Z, all_new);
        if (all_new == 'E' || all_new == 'e') exit(0);
        
        //Open the output file
        char xpause;
        ofstream outdata;
        outdata.open("ZAMSmodel.txt", ios::out);
        if (outdata.fail()){
            cout << " Unable to open output file 'ZAMSmodel.txt' --- Terminating calculation"  
                << "\n\n"
                << "Enter any character to quit: ";
            cin  >> xpause;
            exit(1);
        }

        //Write input data to the output file
        outdata 
            << "                                             "
            << "A ZAMS Stellar Model\n" 
            << "                                             "
            << "--------------------\n" << endl;
        outdata << fixed << showpoint << right << setprecision(5)
            << "                                             " << "M    = " << setw(11) << Msolar << " solar" << "\n"
            << "                                             " << "L    = " << setw(11) << Lsolar << " solar" << "\n"
            << "                                             " << "R    = " << setw(11) << Rsolar << " solar" << "\n"
            << "                                             " << "Teff = " << setw(11) << Teff   << " K    " << "\n"
            << "                                             " << "X    = " << setw(11) << X      << "\n"
            << "                                             " << "Y    = " << setw(11) << Y      << "\n"
            << "                                             " << "Z    = " << setw(11) << Z      << "\n\n\n" << endl;

        //Set up previous zone values
        Pm   = 0;
        Tm   = 0;
        Xm   = X;
        Zm   = Z;
        rm   = Rs;
        taum = 0;
        rhom = 0;
        kappam = 0;
        epsilonm = 0;
        dlnPdlnT = 99.9;
        rc_flag = 'r';

        outdata << " zone      r         tau     1-M_r/Ms      L_r         T          P         rho        "
            << "kap        eps    dlnPdlnT" << endl;

        outdata << setw(5) << i
            << scientific << showpoint << right << setprecision(3)
            << setw(11) << rm
            << setw(11) << 0
            << setw(11) << 0
            << setw(11) << Ls
            << setw(11) << Tm
            << setw(11) << Pm
            << setw(11) << rhom
            << setw(11) << kappam
            << setw(11) << epsilonm
            << "  " << rc_flag
            << fixed << showpoint << right << setprecision(1)
            << setw(5) << dlnPdlnT << endl;

        //Compute surface zones and step size
        double r, P, T, M_r, L_r;
        double P_0, T_0, rho_0, epsilon_0, kappa_0;

        Mm = Ms;
        Lm = Ls;
        double dr = -dr_over_r*Rs;
        step_size_condition = 0;
        
        do{
            i++;

            //Update last zone values
            if (i > 1){
                Mm = M_r;
                Lm = L_r;
                rm = r;
                Pm = P;
                Tm = T;
                Xm = X;
                Zm = Z;
                taum = tau;
                rhom = rho;
                kappam = kappa;
                epsilonm = epsilon;
            }
        
            Surface(i, Mm, Lm, Mm, Lm, rm, Pm, Tm, X, Z, dr, r, P, T, M_r, L_r, rho, kappa, epsilon, 
                dlnPdlnT, gamma, rc_flag, step_size_condition, ok_surface);
            if (!ok_surface) break;

            tau = taum + Optical_Depth_Change(kappa, kappam, rho, rhom, r, rm);
            
            outdata << setw(5) << i
                << scientific << showpoint << right << setprecision(3)
                << setw(11) << r
                << setw(11) << tau
                << setw(11) << 1 - M_r/Ms
                << setw(11) << L_r
                << setw(11) << T
                << setw(11) << P
                << setw(11) << rho
                << setw(11) << kappa
                << setw(11) << epsilon
                << "  " << rc_flag
                << fixed << showpoint << right << setprecision(1)
                << setw(5) << dlnPdlnT << endl;
        } while (i < n_surface);

Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
        double mu;
        if (ok_surface){
            //Load array of first derivatives to start the general inward integration
            Y        = Helium(X, Z);
            mu       = Mean_Molecular_Weight(X, Y, Z);
            gamma    = Specific_Heat_Ratio();
            dlnPdlnT = PTgradient(Pm, P, Tm, T);
            
            dfdr0[0] = dPdr(M_r, rho, r);
            dfdr0[1] = dMdr(r, rho);
            dfdr0[2] = dLdr(r, rho, epsilon);
            dfdr0[3] = dTdr(kappa, rho, T, L_r, r, mu, M_r, gamma, dlnPdlnT, rc_flag);

            //Main inward integration loop
            bool exit_main = false;
            while (!exit_main){
                i++;
                
                //Update last zone values
                Mm = M_r;
                Lm = L_r;
                Pm = P;
                Tm = T;
                Xm = X;
                Zm = Z;
                rm = r;
                taum = tau;
                rhom = rho;
                kappam = kappa;
                epsilonm = epsilon;
        
                double PMLT0[4] = {Pm, Mm, Lm, Tm};
                double PMLT[4];
                RK_4(n, rm, dr, PMLT0, PMLT, dfdr0, ok_Runge, X, Z, Pm, Tm, step_size_condition, rc_flag);
                if (!ok_Runge) exit_main = true;
                
                if (ok_Runge){
                    //Results from the current step
                    P   = PMLT[0];
                    M_r = PMLT[1];
                    L_r = PMLT[2];
                    T   = PMLT[3];

                    //Compute current step quantities for output and next step
                    Y   = Helium(X, Z);
                    mu  = Mean_Molecular_Weight(X, Y, Z);
                    rho = Density(T, P, mu, step_size_condition);
                    kappa    = Opacity(T, rho, X, Z);
                    dlnPdlnT = PTgradient(Pm, P, Tm, T);
                    epsilon  = Nuclear(T, rho, X, Z);
                    
                    dfdr0[0] = dPdr(M_r, rho, r);
                    dfdr0[1] = dMdr(r, rho);
                    dfdr0[2] = dLdr(r, rho, epsilon);
                    dfdr0[3] = dTdr(kappa, rho, T, L_r, r, mu, M_r, gamma, dlnPdlnT, rc_flag);
                    
                    tau = taum + Optical_Depth_Change(kappa, kappam, rho, rhom, rm + dr, rm);

                    outdata << setw(5) << i
                        << scientific << showpoint << right << setprecision(3)
                        << setw(11) << r
                        << setw(11) << tau
                        << setw(11) << 1 - M_r/Ms
                        << setw(11) << L_r
                        << setw(11) << T
                        << setw(11) << P
                        << setw(11) << rho
                        << setw(11) << kappa
                        << setw(11) << epsilon
                        << "  "     << rc_flag
                        << fixed    << showpoint << right << setprecision(1)
                        << setw(5)  << dlnPdlnT  << endl;

                    if ((M_r/Ms < M_fraction_limit && L_r/Ls < L_fraction_limit && r/Rs < r_fraction_limit)
                        || T < 0 || P < 0) exit_main = true;
                    else if (i > maximum_zones) {
                        Too_Many_Zones(i, Msolar, Ms, M_r, Lsolar, Ls, L_r, r, Rs, Rsolar, Teff, X, Y, Z, P_0, T_0, 
                            rho_0, kappa_0, epsilon_0, rc_flag);
                        ok_Runge = false;
                        exit_main = true;}

                    if (!exit_main){
                        //Is it time to change step size?
                        if (adjust_step_size){
                            switch (step_size_condition){
                                case 0:
                                    if (M_r < 0.99*Ms) {
                                        dr = -Rs/100;
                                        step_size_condition = 1;}
                                    break;
                                case 1:
                                    if (fabs(dr) > 5*r) {
                                        dr /= 10;
                                        step_size_condition = 2;}
                                    break;
                            }
                        }
                    }
                }
                
                r += dr;
            }

            //Core_Extrapolation
            if (ok_Runge) {
                //Determine core conditions
                i++;
                Core(M_r, L_r, P, T, X, Z, r, P_0, T_0, rho_0, kappa_0, epsilon_0, rc_flag, dlnPdlnT, ok_core);
                if (!ok_core) {
                    cout << "\nWARNING:  There was a problem with the core extrapolation routine" << endl;}

                tau += Optical_Depth_Change(kappa_0, kappa, rho_0, rho, 0, r);
                outdata << setw(5) << i
                    << scientific << showpoint << right << setprecision(3)
                    << setw(11) << 0
                    << setw(11) << tau
                    << setw(11) << 1 - M_r/Ms
                    << setw(11) << L_r
                    << setw(11) << T_0
                    << setw(11) << P_0
                    << setw(11) << rho_0
                    << setw(11) << kappa_0
                    << setw(11) << epsilon_0
                    << "  " << rc_flag
                    << fixed << showpoint << right << setprecision(1)
                    << setw(5) << dlnPdlnT << endl;
                
                //Write initial and final conditions to the screen
                Final_Results(i, Msolar, Ms, M_r, Lsolar, Ls, L_r, r, Rs, Rsolar, Teff, X, Y, Z,
                    P, T, rho, kappa, epsilon, P_0, T_0, rho_0, kappa_0, epsilon_0, rc_flag);
            }
        }

        //Does the user want to compute a new model?
        all_new = 'Y';
        Change_Model(Msolar, Lsolar, Rsolar, Ms, Ls, Rs, Teff, X, Y, Z, all_new);
        outdata.close();
        if (outdata.fail()){
            cout << " Unable to close the output file - the new model calculation is being aborted"  
                << "\n\n"
                << "Enter any character to quit: ";
            cin  >> xpause;
            exit(1);
        }
    }
    return 0;
}


But when I compile and run it. I got:

C:\Users\ENVY\AppData\Local\Temp\cc05zAGj.o StatStar.cpp:(.text+0x149): undefined reference to `Initial_Model(double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, char&)'

C:\Users\ENVY\AppData\Local\Temp\cc05zAGj.o StatStar.cpp:(.text+0xb30): undefined reference to `Surface(int, double, double, double, double, double, double, double, double, double, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, char&, int, bool&)'

C:\Users\ENVY\AppData\Local\Temp\cc05zAGj.o StatStar.cpp:(.text+0xba0): undefined reference to `Optical_Depth_Change(double, double, double, double, double, double)'

C:\Users\ENVY\AppData\Local\Temp\cc05zAGj.o StatStar.cpp:(.text+0xf19): undefined reference to `Specific_Heat_Ratio()'

C:\Users\ENVY\AppData\Local\Temp\cc05zAGj.o StatStar.cpp:(.text+0xf6a): undefined reference to `PTgradient(double, double, double, double)'

E:\LAPAN\Pemrograman\Pemrograman\ModernAstrophysicsCode[1]\ModernAstrophysicsCode\C++ Source Codes\Appendix L StatStar\collect2.exe [Error] ld returned 1 exit status

How to fix it? Anybody know? Thank you
Last edited on
You fix it by reading the error messages ... one by one .... starting from the top.

The first one says it doesn't find Initial_Model() with this declaration. It's not in your code so it must be in one of the linked files whose headers you have included. YOU need to find which one and check
- have you linked it?
- does your function call match EXACTLY the set of arguments?
- does this file's header tie up with the function definition?

As we haven't got these routines it can only be you who finds them.

Please put your code in code tags.
Thank you for your suggestions. I will try that more careful.
Because I think I have linked those all. But it still doesn't work.

Maybe your second and third questions I haven't do it.

This is one of the files: there are so many files.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*Boundary_Conditions
!
!   General Description:
!   ====================
!       This module contains:
!           (a) the starting conditions for the surface inward integration,
!               assuming that the surface pressure, temperature, and density are all zero.
!           (b) extrapolation formuale to estimate central conditions from the last computed zone
!
!---------------------------------------------------------------------*/

#include <cmath>
#include <iostream>
#include <iomanip>

#include "Constants.h"
#include "Composition.h"
#include "Physics.h"
#include "Stellar_Structure_Equations.h"

void Surface(int i, double Ms, double Ls, double Mm, double Lm, double rm, double Pm, double Tm, double X, double Z, 
             double& dr, double& r, double& P, double& T, double& M_r, double& L_r, double& rho, double& kappa, 
             double& epsilon, double& dlnPdlnT, double& gamma, char& rc_flag, int step_size_condition, bool& good_surface)
{
//  General Description:
//  ====================
//      Estimate the temperature and pressure of the outermost zone from the zero boundary condition.
//      Electron scattering and H- ion contributions to the opacity are neglected for simplification.

    using ModAstroConstants::G;
    using ModAstroConstants::m_H;
    using ModAstroConstants::pi;
    using ModAstroConstants::a_rad;
    using ModAstroConstants::c;
    using ModAstroConstants::k_B;

    const double a = a_rad;
    const double k = k_B;
    const double g_ff = 1;              //the free-free Gaunt factor is on the order of unity
    const double A_bf = 4.34e21;        //the bound-free coefficient
    const double A_ff = 3.68e18;        //the free-free coefficient
    const double maximum = 1.0e-08;     //Maximum change in Ms and Ls over surface zone
    const int j_max = 50;

    r = rm + dr;
    double Y  = Helium(X, Z);
    double mu = Mean_Molecular_Weight(X, Y, Z);
    gamma = Specific_Heat_Ratio();
    double gamma_ratio = gamma/(gamma - 1);

    int j = 0;
    bool exit_outerzone = false;
    while (!exit_outerzone){
        //Compute the temperature and pressure for the radiative boundary condition
        rc_flag = 'r';
        T = G*Ms*(mu*m_H/(4.25*k))*(1/r - 1/rm);        //Eq. (L.2); radiative assumption

        double tog_bf;
        if (i < 2) tog_bf = 0.01;                       //Assume small value for surface
        else tog_bf = 2.82*pow((rho*(1 + X)), 0.2);     //Taken from Novotny (1973), p. 469

        double Aop = (A_bf/tog_bf)*Z*(1+X) + A_ff*g_ff*(1-Z)*(1+X);     //From Eq. (9.22) and (9.23)
        P = sqrt((1/4.25)*(16*pi/3)*(G*Ms/Ls)*(a*c*k/(Aop*mu*m_H)))*pow(T, 4.25);    //Eq. (L.1)

        //If the zone is convective, recompute the adiabatic temperature and pressure
        dlnPdlnT = PTgradient(Pm, P, Tm, T);
        double kPadiabatic;
        if (dlnPdlnT < gamma_ratio && i > 2) {
            rc_flag = 'c';
            kPadiabatic = Pm/pow(Tm, gamma_ratio);
            T = G*Ms*(mu*m_H/(k*gamma_ratio))*(1/r - 1/rm);             //Eq. (L.3)
            P = kPadiabatic*pow(T, gamma_ratio);                        //Eq. (10.83)
        }
        
        //Compute remaining surface quantities
        rho = Density(T, P, mu, step_size_condition);
        if (rho < 0) {
            good_surface = false;
            exit_outerzone = true;
        }
        if (exit_outerzone) break;

        kappa = Opacity(T, rho, X, Z);
        double XCNO = CNO(Z);
        epsilon = Nuclear(T, rho, X, Z);

        //Test to be sure that variations in M_r and L_r are not too large
        M_r = Mm + dMdr(r, rho)*dr;
        L_r = Lm + dLdr(r, rho, epsilon)*dr;
        if (fabs((Ms - M_r)/Ms) < maximum && fabs((Ls - L_r)/Ls) < maximum) {
            good_surface = true;
            exit_outerzone = true;
        }
        if (exit_outerzone) break;

        //If changes in M_r and L_r were too large, repeat with one-half the step size
        j++;
        if (j > j_max) {
            cout << "Unable to converge in Function Surface --- Exiting" << endl;
            good_surface = false;
            exit_outerzone = true;
        }
        if (exit_outerzone) break;

        dr /= 2;
        r = rm + dr;
    }

    if (!good_surface) {
        cout << scientific << showpoint << right << setprecision(6)
            << "The last values obtained by Function Surface were: \n"
            << "     M_r = " << setw(13) << M_r
            << "   dM_r/Ms = " << setw(13) << (Ms - M_r)/Ms << "\n"
            << "     L_r = " << setw(13) << L_r
            << "   dL_r/Ls = " << setw(13) << (Ls - L_r)/Ls << endl;
    }
    return;
}

//---------------------------------------------------------------------

void Core(double M_r, double L_r, double P, double T, double X, double Z, double r, double& P_0, double& T_0, 
          double& rho_0, double& kappa_0, double& epsilon_0, char& rc_flag, double& dlnPdlnT, bool& good_T)
{
//  General Description:
//  ====================
//      This routine extrapolates from the inner-most zone to obtain estimates of core conditions in the star

    using ModAstroConstants::four_pi_o3;
    using ModAstroConstants::two_pi;
    using ModAstroConstants::G;
    using ModAstroConstants::m_H;
    using ModAstroConstants::a_rad_o3;
    using ModAstroConstants::k_B;

    const double a_o3 = a_rad_o3;
    const double k = k_B;
    const double converged = 1.0e-08;
    const int i_max = 50;

    rho_0     = M_r/(four_pi_o3*pow(r, 3));         //Average density of the central ball
    P_0       = P + (two_pi/3)*G*rho_0*rho_0*r*r;   //Central pressure, Eq. (L.4)
    epsilon_0 = L_r/M_r;                            //Average energy generation rate of the central ball

    //Find core temperature by Newton-Raphson method (including radiation pressure)
    double Y   = Helium(X, Z);
    double mu  = Mean_Molecular_Weight(X, Y, Z);

    if (rho_0 > 0) {
        int i = 0;
        T_0 = T;
        double dT;
        good_T = true;
        do {
            i++;
            double f = rho_0*k*T_0/(mu*m_H) + a_o3*pow(T_0, 4) - P_0;   //Ideal Gas Law + Radiation Pressure - core P = 0
            double dfdT = rho_0*k/(mu*m_H) + 4*a_o3*pow(T_0, 3);        //df/dT
            
            dT = -f/dfdT;
            T_0 += dT;

            if (i > i_max) {
                cout << "Unable to converge on core temperature in Function Core --- Exiting" << endl;
                good_T = false;}
        } while (i <= i_max && fabs(dT/T_0) >= converged);
    }
    else {
        T_0 = -T;
        good_T = false;}

    if (good_T) {
        kappa_0  = Opacity(T_0, rho_0, X, Z);
        dlnPdlnT = PTgradient(P, P_0, T, T_0);
        double gamma    = Specific_Heat_Ratio();
        if (dlnPdlnT < (gamma/(gamma - 1))) rc_flag = 'c';
        else rc_flag = 'r';}
    else {
        kappa_0  = -99.9;
        dlnPdlnT = -99.9;
        rc_flag  = '*';}

    return;
}
Last edited on
Go through the header files, one by one, find which contains the declaration of function Initial_Model().

If you don't find it at all then maybe you still need to write that function.

If you do find it, check two things:
a) did you remember to #include that header?
b) does the parameter list (number and type) match those you use when calling the function?


Also - please edit your posts to put the code in code tags. See article for help:
http://www.cplusplus.com/articles/jEywvCM9/

Last edited on
Thank you very much for your suggestions. I must apologize. and make those code tags.
I had a look at your error message for the Surface() call. It was able to identify which parameters were passed by value and which by reference - information which is probably given in the header file Boundary_Conditions.h. This is in accordance with your call.

So, I suspect that you haven't linked a file compiled from Boundary_Conditions.cpp (or whatever file it is whose contents you have just posted). You are clearly managing to link some other routines like RK_4 (probably in ODE_Integrator.cpp), so have a look at what files you are linking together to create an executable. I don't know what compiler or environment you are using. If you are using a makefile then you must be sure that it compiles and links all the necessary files, and that you actually have all the source files (.cpp) accessible.


Well, a bit of googling (search: "stellar_structure_equations.h") led me to:
http://www.physics.utah.edu/~springer/phys3060/Assignments_files/ModernAstrophysicsCode/C++%20Source%20Codes/Appendix%20L%20StatStar/ReadMe.txt

which says that you need to compile and link with the following files:

This folder contains the modules and main routine for StatStar, written in C++.  You will also need Constants.h which is available in the Appendix I folder.

The list of required files to compile and link StatStar are:

StatStar.cpp  (Main Driver routine)
Boundary_Conditions.cpp
Boundary_Conditions.h
Composition.h
ODE_Integrator.cpp
ODE_Integrator.h
Physics.cpp
Physics.h
Stellar_Structure_Equations.cpp
Stellar_Structure_Equations.h
User_IO.cpp
User_IO.h


and from Appendix I:

Constants.h




StatStar is described in Chapter 10 and Appendix L of:

An Introduction to Modern Astrophysics
Bradley W. Carroll and Dale A. Ostlie
Addison Wesley
Copyright 2007.


Make sure that everything in bold is compiled and linked into your executable ... not just StatStar.cpp.

I must say that I'm not a great fan of those long argument lists! Time to define some classes or structs and turn it into genuine c++.
Last edited on
Thank you lastchance. I have compiled it for example the Boundary_Conditions.cpp

But I got:

1
2
3
4
5
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libmingw32.a(lib64_libmingw32_a-crt0_c.o)	In function `main':

C:\crossdev\src\mingw-w64-v3-git\mingw-w64-crt\crt\crt0_c.c	undefined reference to `WinMain'

E:\LAPAN\Pemrograman\Pemrograman\ModernAstrophysicsCode[1]\ModernAstrophysicsCode\C++ Source Codes\Appendix L StatStar\collect2.exe	[Error] ld returned 1 exit status


I downloaded all the files from the reference I gave, replaced StatStar.cpp with your version and added
#include <cstdlib>
to StatStar.cpp and ODE_Integrator.cpp (in order to use exit()).

I put my compile commands in a batch file:
g++ StatStar.cpp Boundary_Conditions.cpp ODE_Integrator.cpp Physics.cpp Stellar_Structure_Equations.cpp User_IO.cpp

and it compiled successfully.

It appears to run OK ...
               StatStar is designed to build a ZAMS star


               Details of the code are described in:
                  An Introduction to Modern Astrophysics
                  Bradley W. Carroll and Dale A. Ostlie
                     Second Edition, Addison Wesley
                     copyright 2007

               The user will be asked to enter the following quantities:
                  Mass of the star       (in solar units)
                  Luminosity of the star (in solar units)
                  Effective Temperature  (in K)
                  Hydrogen mass fraction (X)
                  Metals mass fraction   (Z)

Enter the mass (in solar units)       :

at which point I decided that I didn't know enough about main-sequence stars to continue!


I don't know much about dev-c++, I'm afraid, but I suspect that your IDE should be set to create a console app (int main) , rather than a Win GUI app (WinMain) ... or something like that. See http://www.cplusplus.com/forum/beginner/211576/#msg990622 (@Thomas1965's reply).

It's an issue with your use of an IDE, not the source code per se.
Last edited on
Topic archived. No new replies allowed.