CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   At runtime, undefined symbol error from classes derived from Function1 class (https://www.cfd-online.com/Forums/openfoam-programming-development/207696-runtime-undefined-symbol-error-classes-derived-function1-class.html)

doctorWho September 30, 2018 12:37

At runtime, undefined symbol error from classes derived from Function1 class
 
Hi,


I am trying to make classes with template pattern from Function1 class with OpenFOAM 5.
compilation was done without any errors and warnings.


There is an error in runtime as follows:


simpleFoam: symbol lookup error: /home/abs/OpenFOAM/abs-6/platforms/linux64GccDPInt32Opt/lib/libFlowProfile.so: undefined symbol: _ZN4Foam14Function1Types15FlowProfileINS_6VectorId EEEC2ERKNS_4wordERKNS_10dictionaryE


classes are composed as follows:


Function1 <--- FlowProfile <--- uniformProfile


where FlowProfile is a abstract template class and uniformProfile is a derived class with vector binding.


without FlowProfile abstract class, I could make uniformProfile working in my simulation. But I want to make a group of my flow profiles with FlowProfile abstract class.



It is a kind of template class things, so I could not figure out what is going on and how to fix the runtime error. Any help will be appreciated.


FYI, source codes are listed below.



FlowProfile classes read as follows:



#ifndef FlowProfile_H
#define FlowProfile_H

#include "Function1.H"

namespace Foam
{
namespace Function1Types
{

template<class Type>
class FlowProfile
:
public Function1<Type>
{
protected:

scalar uRef_;
scalar zRef_;

vector flowDir_;

private:

void read(const dictionary& coeffs);
void operator=(const FlowProfile<Type>&);

public:

FlowProfile
(
const word& entryName,
const dictionary& dict
);


virtual ~FlowProfile();

virtual Type value(const scalar t) const = 0;

};

} // End namespace Function1Types
} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#define makeVectorFunction1(SS) \
\
defineTypeNameAndDebug(SS, 0); \
\
Function1<vector>::adddictionaryConstructorToTable <FieldFunction1<SS>> \
add##SS##ConstructorToTable_;

#endif

// ************************************************** *********************** //





FlowProfile.C


#include "FlowProfile.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

template<class Type>
void Foam::Function1Types::FlowProfile::read(const dictionary& coeffs)
{
uRef_ = coeffs.lookup<scalar>("uRef");
zRef_ = coeffs.lookup<scalar>("zRef");
flowDir_ = coeffs.lookupType<vector>("flowDir");
}

template<class Type>
Foam::Function1Types::FlowProfile<Type>::FlowProfi le
(
const word& entryName,
const dictionary& dict
)
:
Function1<Type>(entryName)
{
read(dict);
}


// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //

template<class Type>
Foam::Function1Types::FlowProfile<Type>::~FlowProf ile()
{}



uniformProfile classes read as follows:


#ifndef uniformProfile_H
#define uniformProfile_H

#include "FlowProfile.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
namespace Function1Types
{

class uniformProfile
:
public FlowProfile<vector>
{
void operator=(const uniformProfile&);

public:

TypeName("uniformProfile");

uniformProfile
(
const word& entryName,
const dictionary& dict
);


virtual ~uniformProfile();

virtual inline vector value(const scalar t) const;
virtual void writeData(Ostream& os) const;

};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Function1Types
} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#include "uniformProfileI.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif




uniformProfileI.H


#include "uniformProfile.H"

// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

inline Foam::vector Foam::Function1Types::uniformProfile::value
(
const scalar t
) const
{
return uRef_*flowDir_;
}




uniformProfile.C


#include "uniformProfile.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
namespace Function1Types
{
makeVectorFunction1(uniformProfile);
}
}


// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

Foam::Function1Types::uniformProfile::uniformProfi le
(
const word& entryName,
const dictionary& dict
)
:
FlowProfile(entryName, dict)
{}


// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //

Foam::Function1Types::uniformProfile::~uniformProf ile()
{}

// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

void Foam::Function1Types::uniformProfile::writeData(Os tream& os) const
{
Function1<vector>::writeData(os);
os << token::END_STATEMENT << nl;
os << indent << word(this->name() + "Coeffs") << nl;
os << indent << token::BEGIN_BLOCK << incrIndent << nl;
os.writeKeyword("uRef") << uRef_ << token::END_STATEMENT << nl;
os.writeKeyword("zRef") << zRef_ << token::END_STATEMENT << nl;
os.writeKeyword("flowDir") << flowDir_ << token::END_STATEMENT << nl;
os << decrIndent << indent << token::END_BLOCK << endl;
}


Make/files reads as follows:
unction1/FlowProfile/uniformProfile/uniformProfile.C
LIB = $(FOAM_USER_LIBBIN)/libFlowProfile


Make/options reads as follows:
EXE_INC = \
-I$(OBJECTS_DIR) \
-I$(LIB_SRC)/OpenFOAM/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/transportModels \
-I$(LIB_SRC)/transportModels/incompressible/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude

LIB_LIBS = \
-lfiniteVolume \
-lmeshTools


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