CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   undefined reference when adding new member function (http://www.cfd-online.com/Forums/openfoam-programming-development/88428-undefined-reference-when-adding-new-member-function.html)

dohnie May 17, 2011 11:08

undefined reference when adding new member function
 
Hello,
this has cost me six hours so far:

I want to add a new member function to the hCombustionThermo class. I've boiled it down to the simplest possbile problem. In hCombustionThermo.H I write:
Code:

  void hello();
It compiles fine.

In my solver (based on reactingFoam) I write:
Code:

Info<< nl << "Reading thermophysicalProperties" << endl;
autoPtr<hPsiChemistryModel> pChemistry
(
    hPsiChemistryModel::New(mesh)
);
hPsiChemistryModel& chemistry = pChemistry();
hCombustionThermo& thermo = chemistry.thermo();

thermo.hello();    // the only change

It seems that compiling works, but during the linking process an error occurs:

Code:

g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -O3  -DNoRepository -ftemplate-depth-40 -I/nfs/opt/OpenFOAM/OpenFOAM-1.7.1/src/finiteVolume/lnInclude    -I/nfs/opt/OpenFOAM/OpenFOAM-1.7.1/src/turbulenceModels/compressible/turbulenceModel    -I/nfs/opt/OpenFOAM/OpenFOAM-1.7.1/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/mutWallFunctions    -I/nfs/opt/OpenFOAM/OpenFOAM-1.7.1/src/turbulenceModels/compressible/RAS/lnInclude    -I/nfs/home/ettner/OpenFOAM/ettner-1.7.1/src/thermophysicalModels/reactionThermo/lnInclude    -I/nfs/home/ettner/OpenFOAM/ettner-1.7.1/src/thermophysicalModels/basic/lnInclude    -I/nfs/home/ettner/OpenFOAM/ettner-1.7.1/src/thermophysicalModels/specie/lnInclude    -I/nfs/home/ettner/OpenFOAM/ettner-1.7.1/src/thermophysicalModels/chemistryModel/lnInclude    -I/nfs/opt/OpenFOAM/OpenFOAM-1.7.1/src/engine/lnInclude    -I/nfs/opt/OpenFOAM/OpenFOAM-1.7.1/src/ODE/lnInclude    -I/nfs/home/ettner/OpenFOAM/ettner-1.7.1/applications/solvers/flameTracing    -I/nfs/home/ettner/OpenFOAM/ettner-1.7.1/src/interpolationLookUpTable -IlnInclude -I. -I/nfs/opt/OpenFOAM/OpenFOAM-1.7.1/src/OpenFOAM/lnInclude -I/nfs/opt/OpenFOAM/OpenFOAM-1.7.1/src/OSspecific/POSIX/lnInclude  -fPIC Make/linux64Gcc43DPOpt/ddtLookup.o -L/nfs/opt/OpenFOAM/OpenFOAM-1.7.1/lib/linux64Gcc43DPOpt \
            -L/nfs/home/ettner/OpenFOAM/ettner-1.7.1/lib/linux64Gcc43DPOpt    -lmyreactionThermophysicalModels    -lmybasicThermophysicalModels    -lmychemistryModel    -lmyspecie    -lfiniteVolume    -lcompressibleRASModels    -lcompressibleLESModels    -lengine    -lODE -lOpenFOAM -liberty -ldl  -lm -o /nfs/home/ettner/OpenFOAM/ettner-1.7.1/applications/bin/linux64Gcc43DPOpt/ddtLookup
Make/linux64Gcc43DPOpt/ddtLookup.o: In function `main':
ddtLookup.C:(.text+0x1bbd): undefined reference to `Foam::hCombustionThermo::hello()'
collect2: ld returned 1 exit status
make: *** [/nfs/home/ettner/OpenFOAM/ettner-1.7.1/applications/bin/linux64Gcc43DPOpt/ddtLookup] Error 1

Can anybody explain me what I'm doing wrong?

r08n May 17, 2011 12:00

[QUOTE=dohnie;307983]
I want to add a new member function to the hCombustionThermo class. I've boiled it down to the simplest possbile problem. In hCombustionThermo.H I write:
Code:

  void hello();
You declare a function, but not define it. Try this:
Code:

void hello (){}
In general, you better not modify the existing OF classes like this.
If you need to extend some class, declare your own class inherited from the existing class, like this:
Code:

class my_hCombustionThermo : public hCombustionThermo
{
  void hello () {}
};


marupio May 17, 2011 12:06

You have a prototype for the hello() function, but no implementation of it. That is causing the problem you posted. I think you may have boiled it down too far?

dohnie May 19, 2011 04:31

Thanks to both of you, I'll give it another try!


All times are GMT -4. The time now is 07:17.