CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Running, Solving & CFD (
-   -   Compilation error "Foam::xyz has not been declared" (

Arnoldinho August 22, 2011 12:28

Compilation error "Foam::xyz has not been declared"
Hi all,

I guess this is a simple questions to all of you knowing c++ programming, but I don't get it right now:

I have a file test.C including a function call

variable = Foam::xyz::method(a, b, c);
The file xyz.C (including a xyz.H header file) has a function called "method", returning a value. Both are in the same folder.

When compiling, I get the error message

test.C:31: error: ‘Foam::xyz’ has not been declared
When putting the above function call directly into main() in xyz.C, it compiles without an error.

What do I have to include at which position, so that the function call finds my function?


kathrin_kissling August 23, 2011 03:09

Hello Arne,

did you

#inlcude "xyz.H"

into your main file?

Did you compile the xyz.C?



Arnoldinho August 23, 2011 12:48

Hi Kathrin,

thanks for the hint with compiling xyz.C. This itself originally compiled before, but due to some changes, it maybe could not be found now.
Including xyz.C in my test.C now solved it. But is including a .C file via #include a good idea? Normally, I only do this with header files. Alternatively, how do I compile the single xyz.C file before? wmake xyz.C gives

Für das Ziel »computeUbNewton.C« ist nichts zu tun.

wyldckat August 23, 2011 17:38

Greetings to all!

@Arne: have you ever done the following exercise?

I'll give you a hint :) "Make/files":

Now go into the Make subdirectory and open the 'files' file with your favorite editor. Change it to read:


EXE = $(FOAM_USER_APPBIN)/my_icoFoam

Best regards,

Arnoldinho August 24, 2011 02:43

Thanks Bruno,

I know this exercise ;). For me it's not straight forward due to the fact that I have two C-files test.C and xyz.C, whereas test.C holds the main() function and xyz.C only some methods which have to be called from within test.C

For "compile the single xyz.C file before" I meant something like g++ xyz.C with additional arguments (as this does not know the Foam files).

Nevertheless, #include xyz.C works so far.


kathrin_kissling August 24, 2011 02:49


do you have a Make folder in your directory?

The just edit the "file" file and add



EXE = $(FOAM_USER_APPBIN)/test //or whatever you wanna call it

Then add the #include "xyz.H" file to your solver.
Run wmake.

Just try!

akidess August 24, 2011 02:52

To build upon Bruno's answer, the usual way to write the makefile is:



EXE = $(FOAM_USER_APPBIN)/my_icoFoam

If you want to call a function from xyz.C in main.C, all you have to do is declare (but not define) the function in a header file and include it in main.C. Including the C-file directly is not forbidden, but generally not recommended.

kathrin_kissling August 24, 2011 02:56

Now I got it.

Thank you Anton for making this point for me.

There's no .H file. I was so much into the nomal class structure, so I totally misunderstood. I never wanted to include some .C file.

Maybe it would be a good idea to program that way that it will match the normal OpenFOAM structure but its not necessary. You may find the fowmNew scripts quite helpfull. There's a link in the wiki. I just cannot remember.



Arnoldinho August 24, 2011 03:07

Thanks to all, now I got it as well ;).


florian_krause August 31, 2011 05:22

I think I have a similar problem as reported by Arne.

I have solver (its structure is similar to pisoFoam) and I would like to add an overloaded function (lets call the function simple). The function looks like


volScalarField simple(volScalarField& unfiltered)
  return fvc::surfaceSum

I want to overload the function, so that it takes / returns volVectorField and volTensorField as well.

What I did so far:

I have a file simplefilter.C with the code above and a file simplefilter.H which contains


volScalarField simple(volScalarField& unfiltered);
in the solver I included the header file simple.H and in ./Make/files I added simplefilter.C

Hope it is not confusing so far?! :)

Now, this is already pretty messed up and running wmake gives me the expected error: volScalarField, volVectorField and volTensorField do not name a type. Well, I don't include the corresponding headers like fvCFD.H etc. in simplefilter.C which probably cause the error...

My question, is there a more simple (also elegant) way to add an overloaded function as the one mentioned above to a solver? Any hints are much appreciated!


wyldckat September 1, 2011 17:29

Greetings Florian,

OK, when in doubt: isolate and conquer!

Step one: put your new functions in the same file as the main .C file and put them before the main function, but after the includes. This way you know the definitions are available on-site.

Step two: replace said functions with a single include of a header that has those functions. Seems pointless, but it's a helpful mnemonic.

Step three:
  1. Move those functions to an independent newStuff.C file;
  2. but leave the prototypes in the header, along with one of those "use me only once" ifndef+define.
  3. Add at least 2 includes to the new newStuff.C file: fvCFD.h and newStuff.H.
  4. Add newStuff.C to make/files.

The premise for this last step: fvCFD.H is included before newStuff.H, therefore the necessary definitions are ready to be used when the compiler seems the newStuff.H file.

Best regards,

All times are GMT -4. The time now is 15:39.