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

Putting functions different files, linker error (undefined reference)

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   November 21, 2012, 09:52
Default Putting functions different files, linker error (undefined reference)
  #1
New Member
 
Christian
Join Date: Jan 2011
Posts: 5
Rep Power: 6
Krischan is on a distinguished road
Hey everyone,
I'm currently working on a solver and wrote some functions I would like to put in a second .C file (not the main solver code).

I wrote a file helperFunctions.H
Code:
#include "fvCFD.H"

namespace Foam {
template<class Type>
void printField(OSstream& output, const GeometricField<Type, fvPatchField, volMesh>& vf);
}
}
And have the definition of that function in helperFunctions.C
Code:
#include "helperFunctions.H"
namespace Foam {
template<class Type>
void printField(OSstream& output, const GeometricField<Type, fvPatchField, volMesh>& vf) {
    forAll (vf.internalField(),icell) {
        output << vf.internalField()[icell] << " ";
    }
}
}
I also added helperFunctions.C to Make/files
My main solver as well as helperFunctions.C compile fine, but when it comes to linking I get the error message

Code:
 undefined reference to `void Foam::printField<double>(Foam::OSstream&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&)'
Obviously I'm doing something wrong here, but I don't see the reason, so any help is appreciated.

Thanks,
Christian
Krischan is offline   Reply With Quote

Old   November 21, 2012, 15:25
Default
  #2
New Member
 
Christian
Join Date: Jan 2011
Posts: 5
Rep Power: 6
Krischan is on a distinguished road
Okay, after reading my Stroustrup and the C++ FAQ I got it.
It's because of how templates work... Time to refresh my C++ Skills, I guess
Krischan is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Water subcooled boiling Attesz CFX 7 January 5, 2013 04:32
libnurbs++ kuczmas OpenFOAM Running, Solving & CFD 7 May 14, 2012 06:33
G95 + CGNS Bruno Main CFD Forum 1 January 30, 2007 01:34
Two-Phase Buoyant Flow Issue Miguel Baritto CFX 4 August 31, 2006 12:02
Building OpenFoAm on SGI Altix 64bits anne OpenFOAM Installation 8 June 15, 2006 09:27


All times are GMT -4. The time now is 01:30.