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

Compilation error "Foam::xyz has not been declared"

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By akidess

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 22, 2011, 12:28
Default Compilation error "Foam::xyz has not been declared"
  #1
Senior Member
 
Arne Stahlmann
Join Date: Nov 2009
Location: Hanover, Germany
Posts: 209
Rep Power: 17
Arnoldinho is on a distinguished road
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
Quote:
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
Quote:
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?

Arne
Arnoldinho is offline   Reply With Quote

Old   August 23, 2011, 03:09
Default
  #2
Senior Member
 
Kathrin Kissling
Join Date: Mar 2009
Location: Besigheim, Germany
Posts: 134
Rep Power: 17
kathrin_kissling is on a distinguished road
Hello Arne,

did you

#inlcude "xyz.H"

into your main file?

Did you compile the xyz.C?

Best

Kathrin
kathrin_kissling is offline   Reply With Quote

Old   August 23, 2011, 12:48
Default
  #3
Senior Member
 
Arne Stahlmann
Join Date: Nov 2009
Location: Hanover, Germany
Posts: 209
Rep Power: 17
Arnoldinho is on a distinguished road
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
Quote:
Für das Ziel »computeUbNewton.C« ist nichts zu tun.
Arne
Arnoldinho is offline   Reply With Quote

Old   August 23, 2011, 17:38
Default
  #4
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Greetings to all!

@Arne: have you ever done the following exercise? http://openfoamwiki.net/index.php/Ho...ure_to_icoFoam

I'll give you a hint "Make/files":
Quote:
Now go into the Make subdirectory and open the 'files' file with your favorite editor. Change it to read:
Code:
my_icoFoam.C

EXE = $(FOAM_USER_APPBIN)/my_icoFoam
Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   August 24, 2011, 02:43
Default
  #5
Senior Member
 
Arne Stahlmann
Join Date: Nov 2009
Location: Hanover, Germany
Posts: 209
Rep Power: 17
Arnoldinho is on a distinguished road
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.

Arne
Arnoldinho is offline   Reply With Quote

Old   August 24, 2011, 02:49
Default
  #6
Senior Member
 
Kathrin Kissling
Join Date: Mar 2009
Location: Besigheim, Germany
Posts: 134
Rep Power: 17
kathrin_kissling is on a distinguished road
Arne,

do you have a Make folder in your directory?

The just edit the "file" file and add

Code:
xyz.C
test.C

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!
kathrin_kissling is offline   Reply With Quote

Old   August 24, 2011, 02:52
Default
  #7
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29
akidess will become famous soon enough
To build upon Bruno's answer, the usual way to write the makefile is:

Code:
xyz.C
main.C

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.
Arnoldinho likes this.
akidess is offline   Reply With Quote

Old   August 24, 2011, 02:56
Default
  #8
Senior Member
 
Kathrin Kissling
Join Date: Mar 2009
Location: Besigheim, Germany
Posts: 134
Rep Power: 17
kathrin_kissling is on a distinguished road
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.

Best

Kathrin
kathrin_kissling is offline   Reply With Quote

Old   August 24, 2011, 03:07
Default
  #9
Senior Member
 
Arne Stahlmann
Join Date: Nov 2009
Location: Hanover, Germany
Posts: 209
Rep Power: 17
Arnoldinho is on a distinguished road
Thanks to all, now I got it as well .

Arne
Arnoldinho is offline   Reply With Quote

Old   August 31, 2011, 05:22
Default
  #10
Senior Member
 
Florian Krause
Join Date: Mar 2009
Location: Munich
Posts: 103
Rep Power: 17
florian_krause is on a distinguished road
Hi,
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

Code:
volScalarField simple(volScalarField& unfiltered)
{
  return fvc::surfaceSum
    (
        mesh().magSf()*fvc::interpolate(unfiltered)
    )/fvc::surfaceSum(mesh().magSf());
}
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

Code:
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!

Best,
Florian
florian_krause is offline   Reply With Quote

Old   September 1, 2011, 17:29
Default
  #11
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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,
Bruno
__________________

Last edited by wyldckat; September 1, 2011 at 17:30. Reason: typos found after posting...
wyldckat 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
errors during compilation and installation of OpenFOAM-1.7.x on Ubuntu 10.04 ftec OpenFOAM Installation 7 February 23, 2011 06:07
Compilation Order and Single Precision Issues gocarts OpenFOAM Bugs 1 October 14, 2009 17:19
Compilation error with uparm.f Raghu Siemens 2 May 30, 2007 02:09
Compilation Error.... Arnab Siemens 4 September 12, 2004 15:54


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