CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   problems with compiling self defined class (https://www.cfd-online.com/Forums/openfoam/77154-problems-compiling-self-defined-class.html)

Victor June 15, 2010 03:51

problems with compiling self defined class
 
Hi at all,

i tried to implement my own class(class Tracing) which follows the flameFront and writes the current position of the flame to a file.
So i wrote two files:

Tracing.H

Tracing.C

After including flameTrace.H in my solver and creating an Object of this class by
...
Tracing flameTip;
...
and using the two methods for following the flame and write the position to the file, by:

flameTip.follow();
...
flameTip.write();

I allways get this error message while compiling the solver:


Make/linux64GccDPOpt/reactingTotalFoamFE2.o: In function `main':
reactingTotalFoamFE2.C:(.text+0x338f): undefined reference to `main::Tracing::Tracing()'
reactingTotalFoamFE2.C:(.text+0x9bdf): undefined reference to `main::Tracing::~Tracing()'
reactingTotalFoamFE2.C:(.text+0xa74b): undefined reference to `main::Tracing::follow()'
reactingTotalFoamFE2.C:(.text+0xa79e): undefined reference to `main::Tracing::writeToFile()'
reactingTotalFoamFE2.C:(.text+0xdb2a): undefined reference to `main::Tracing::~Tracing()'
collect2: ld returned 1 exit status
make: *** [/nfs/home/fleischer/OpenFOAM/fleischer-1.6.x/applications/bin/linux64GccDPOpt/reactingTotalFoamFE2] Error 1

I don't know what "undefined reference to main::Tracing::....." shoud mean!?:confused:

Can anybody help me please!

Thanks a lot in advance!

Victor

l_r_mcglashan June 15, 2010 04:19

That seems odd. Have you changed Make/options and/or Make/files as well? Is this part of a library or are you compiling it with the solver?

And are you sure you meant flameTrace.H instead of Tracing.H:

Quote:

After including flameTrace.H in my solver and creating an Object of this class by

Victor June 15, 2010 05:02

Thank you l_r_mcglashan, I think there are different problems but the basic one is that i didn't know that i need a make-folder for compiling the header file correctly.
I think i will try the whole thing in a easier way....but thanks a lot for your help!

l_r_mcglashan June 15, 2010 05:07

Grabbing an example from the sources, have a look at the application heatTransfer/chtMultiRegionFoam. See how the regionProperties class is used.

Victor June 15, 2010 05:38

Thank you, the regionProperties helps a lot. The problem I have at the moment is that my class Tracing needs the mesh information for calculating the flame position. For example I have to use mesh.C(). I don't know how to handle this, because I don't know how to deliver the mesh Information to my header file.
I tried to use a genererell objectRegistry in the the constructor Tracing(objectRegistry reg0,...), but there doesn't exist a .C() data.
Perhaps you know an example of an header-file that uses the mesh data in any way!?
Something i also do not understand is the declaration of a namespace
namespace Foam
{.....
...}

before the declaration of the class. Could you explain to me, why this is necessary?
Thanks a lot in advance!

Victor

l_r_mcglashan June 15, 2010 06:11

Pass the mesh as an argument to the constructor:

header file:

Code:

       
class Tracing
{
    const fvMesh& mesh_;

    Tracing
    (
        const fvMesh& mesh
    );
}

source file:
Code:

Foam::Tracing::Tracing
(
    const fvMesh& mesh
)
:
    mesh_(mesh)
{}

Then you can use mesh_ in that class.

The Foam namespace isn't declared before the class,. The class is part of the namespace Foam. So Foam::regionProperties is its full name. In chtMultiRegionFoam.C you'll see:

regionProperties rp(runTime);

The full type would be Foam::regionProperties rp(runTime); but in the fvCFD.H file there's a using namespace Foam declaration.

Victor June 21, 2010 02:54

Oh, thank you really much! This is exactly I was looking for!:)


All times are GMT -4. The time now is 13:34.