CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

undefined reference encountered when linking with addToRunTimeSelectionTable

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By jsmiles

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 4, 2011, 07:11
Default undefined reference encountered when linking with addToRunTimeSelectionTable
  #1
New Member
 
Jeff Miles
Join Date: Sep 2011
Posts: 2
Rep Power: 0
jsmiles is on a distinguished road
I am attempting to override/extend the hsCombustionThermo and one of the associated mixture classes (using basicMultiComponentMixture as the base class). These classes are both template classes and the CombustionThermo class has a dual inheritance (using baseHsCombustionThermo and the mixture class -- defined in the template). All appears well until I add the runtime selection to the constructor table. The runtime version of the class needs a hierarchy of templates -- combustion thermo class, mixture class, transport class, species class, thermo properties class, and an equation of state00 class. With that I am using the macros for defineTemplate type and addToRunTimeSelectionTable. Here is the snippet:

namespace Foam
{
typedef mixhsCombustionThermo
<singleComponentMixture <constTransport <specieThermo <hConstThermo<perfectGas>>>>>
mixhsCombustionThermo##singleComponentMixture##con stTransport##hConstThermo##perfectGas;

defineTemplateTypeNameAndDebugWithName
(
mixhsCombustionThermo##singleComponentMixture##con stTransport##hConstThermo##perfectGas,
#mixhsCombustionThermo
"<"#singleComponentMixture"<"#constTransport"<spec ieThermo<"#hConstThermo"<"#hConstThermo">>>>>",
0
);

addToRunTimeSelectionTable
(
baseHsCombustionThermo,
mixhsCombustionThermo##singleComponentMixture##con stTransport##hConstThermo##perfectGas,
theMesh
)
}

This appears to compile fine, but in the final linking of the application the linker complains that it has an undefined reference to the constructor.
-------------------------------------------------------------
undefined reference to 'Foam::mixhsCombustionThermo<Foam::singleComponent Mixture< Foam::constTransport<Foam::specieThermo<Foam::hCon stThermo<FoamerfectGas>>>>>::mixhsCombustionThermo (Foam::fvMesh const&)'
--------------------------------------------------------------
Here are the templates from the base class:

--------------Header----------------------
//- Declare run-time constructor selection tables
declareRunTimeSelectionTable
(
autoPtr,
baseHsCombustionThermo,
theMesh,
(const Foam::fvMesh& mesh),
(mesh)
);

--------------- Impl (C file) -----------------------

namespace Foam
{
defineTypeNameAndDebug(baseHsCombustionThermo, 0);
defineRunTimeSelectionTable(baseHsCombustionThermo , theMesh);
}

and the constructor looks like this:

template<class MixtureType>
Foam::mixhsCombustionThermo<MixtureType>::mixhsCom bustionThermo(const Foam::fvMesh& mesh)
:
hsCombustionThermo(mesh),
MixtureType(*this, mesh)
{
...


---------------------------------------------------------------

If anyone has some experience with this or can see any obvious reasons for the failed reference, your help would be greatly appreciated.

Thanks,

Jeff
jsmiles is offline   Reply With Quote

Old   September 5, 2011, 05:55
Default
  #2
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
l_r_mcglashan will become famous soon enough
Unfortunately templates always 'compile fine', then chuck out horrible errors upon linking!

I have done this myself from scratch before. I assume you've put the constructor method in the .C file and added the .C file to Make/files?
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   September 6, 2011, 18:26
Default Thanks
  #3
New Member
 
Jeff Miles
Join Date: Sep 2011
Posts: 2
Rep Power: 0
jsmiles is on a distinguished road
Laurence,

Thanks,

After reading you comments and thinking of how templates classes work I decided to investigate how the template classes are instantiated. As you already know template classes just sit in the code until they are instantiated. Usually this is done at the time they are used as the example

myClassName<parameters> myClassObj();

Unfortunately in the case of the runtime selection table, the invocation is hard to locate. I found another forum post on the stackoverflow.com website that suggested instantiating the class directly in the shared library so that it is present in the shared library prior to the final linking step. This is done via

template class myClassName<parameters>;

So with all the above said, I was finally able to link my final application by adding an explicit instantiation step in the class C file like the following.

template class Foam::mixhsCombustionThermo < Foam::singleComponentMixture < Foam::constTransport < Foam::specieThermo < Foam::hConstThermo < Foam:erfectGas> > > > >;

Do you know if there is another macro in the OpenFoam source code that does the above instantiation? Or have I stepped outside the bounds of what the OpenFoam infrastructure was intended for here?

Thanks,

Jeff
serles likes this.
jsmiles is offline   Reply With Quote

Old   September 7, 2011, 03:58
Default
  #4
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
l_r_mcglashan will become famous soon enough
Possibly defineTemplateRunTimeSelectionTable? You can find the macros using the doxygen source code browser on the OF website.

I see you did use that. I'll have to look in more detail.

Back. I used the following in my base class .H:

Code:
#define makeOpSplitType(SS, Type)                                             \
                                                                              \
defineNamedTemplateTypeNameAndDebug(SS<Type>, 0);                             \
                                                                              \
operatorSplit<Type>::addopSplitConstructorToTable<SS<Type> >                  \
    add##SS##Type##ConstructorToTable_;

#define makeOpSplitScheme(SS)                                                 \
                                                                              \
makeOpSplitType(SS, scalar)
and in the derived class .C file: makeOpSplitScheme(firstOrderSplit)
__________________
Laurence R. McGlashan :: Website

Last edited by l_r_mcglashan; September 7, 2011 at 04:23. Reason: Correction
l_r_mcglashan is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Second Derivative Zero - Boundary Condition fu-ki-pa OpenFOAM 11 March 27, 2021 04:28
Error with Wmake skabilan OpenFOAM Installation 3 July 28, 2009 00:35
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 19:08
G95 + CGNS Bruno Main CFD Forum 1 January 30, 2007 00:34
Building OpenFoAm on SGI Altix 64bits anne OpenFOAM Installation 8 June 15, 2006 09:27


All times are GMT -4. The time now is 06:27.