1

This question is about openFoam (foam extend v4) C++ but I believe the issue I have is a fundamental C++ programming problem.

I am trying to use the function autoCreateOmega whose prototype can be found in

foam-extend-4.0/src/turbulenceModels/incompressible/RAS/lnInclude/backwardsCompatibilityWallFunctions.H and the definition is in the corresponding backwardsCompatibilityWallFunctions.C.

In my solver.C file I have the following at the top:

#include "fvCFD.H"
#include "simpleControl.H"
#include "wallDist.H"
#include "backwardsCompatibilityWallFunctions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
#   include "setRootCase.H"
#   include "createTime.H"
#   include "createMesh.H"

    simpleControl simple(mesh);

#   include "createFields.H"

And part of my createFields.H looks like this:

    Info<< "Reading field omega\n" << endl;


    volScalarField omega
    (
        IOobject
        (
            "omega",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        //mesh
        autoCreateOmega("omega", mesh, U.db())
    );

When I try to compile this solver I get the following error:

In file included from solver.C:48:0:
 createFields.H: In function ‘int main(int, char**)’:
createFields.H:50:46: error: ‘autoCreateOmega’ was not declared in this scope
         autoCreateOmega("omega", mesh, U.db())
                                              ^
createFields.H:50:46: note: suggested alternative:
In file included from solver.C:37:0:
/home/foam/foam-extend-4.0/src/turbulenceModels/incompressible/RAS/lnInclude/backwardsCompatibilityWallFunctions.H:98:25: note:   ‘Foam::incompressible::autoCreateOmega’
     tmp<volScalarField> autoCreateOmega
                         ^
solver.dep:714: recipe for target 'Make/linux64GccDPOpt/solver.o' failed
make: *** [Make/linux64GccDPOpt/solver.o] Error 1

why doesnt including "backwardsCompatibilityWallFunctions.H" allow me to use autoCreateOmega in my program? Any help is much appreciated.

Please let me know if more information is required.

Edit

In "backwardsCompatibilityWallFunctions.H":

#ifndef backwardsCompatibilityWallFunctions_H
#define backwardsCompatibilityWallFunctions_H

#include "fvMesh.H"

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

namespace Foam
{
namespace incompressible
{


//- omega
tmp<volScalarField> autoCreateOmega
(
    const word& fieldName,
    const fvMesh& mesh,
    const objectRegistry& obj
);

tmp<volScalarField> autoCreateOmega
(
    const word& fieldName,
    const fvMesh& mesh
);

And in "backwardsCompatibilityWallFunctions.C"

tmp<volScalarField> autoCreateOmega
(
    const word& fieldName,
    const fvMesh& mesh,
    const objectRegistry& obj
)
{
    return
        autoCreateWallFunctionField
        <
            scalar,
            RASModels::omegaWallFunctionFvPatchScalarField
        >
        (
            fieldName,
            mesh,
            obj
        );
}


tmp<volScalarField> autoCreateOmega
(
    const word& fieldName,
    const fvMesh& mesh
)
{
    return
        autoCreateWallFunctionField
        <
            scalar,
            RASModels::omegaWallFunctionFvPatchScalarField
        >
        (
            fieldName,
            mesh,
            mesh
        );
}

As suggested: If I add using Foam::incompressible::autoCreateOmega;

Make/linux64GccDPOpt/solver.o: In function `main':
solver.C:(.text.startup+0x7dd): undefined reference to `Foam::incompressible::autoCreateOmega(Foam::word const&, Foam::fvMesh const&, Foam::objectRegistry const&)'
collect2: error: ld returned 1 exit status
/home/foam/foam-extend-4.0/wmake/Makefile:159: recipe for target '/home/foam/applications/bin/linux64GccDPOpt/solver' failed
make: *** [/home/foam/applications/bin/linux64GccDPOpt/solver] Error 1
Community
  • 1
  • 1
Dipole
  • 1,840
  • 2
  • 24
  • 35

1 Answers1

1

Since the compiler informed about not declared function, and not about ambiguous call, the most possible reason is function name is placed in some namespace. I have looked on extended OpenSOAP sources and suggest you to insert using Foam::incompressible::autoCreateOmega; before main.

273K
  • 29,503
  • 10
  • 41
  • 64
  • Thanks for the input, however there are two implementations in the header file, one which accepts two arguments and another which accepts three. Please let me know what else I can provide in terms of source code! – Dipole Aug 13 '18 at 04:34
  • You are likely to use unofficial OpenFOAM library. – 273K Aug 13 '18 at 04:50
  • Yes I am using the foam-extend-v4 branch. However the problem is more about fundamental C++ errors. – Dipole Aug 13 '18 at 05:05
  • You have moved forward. Now compilation is successful but linker failed. You do not supply OpenFOAM library to linker. It is another problem. Look at https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – 273K Aug 13 '18 at 08:03
  • So how do I find out which library I need to include? I assume I need to add it to my Make/options file, but as far as I can tell I have added everything. The reason I think this is because `autoCreateOmega` is used by the turbulence model classes and I have copied all the libraries needed for that compilation. – Dipole Aug 14 '18 at 00:17