CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Compiling a new thermophysical model (https://www.cfd-online.com/Forums/openfoam-programming-development/225343-compiling-new-thermophysical-model.html)

stockzahn March 24, 2020 06:28

Compiling a new thermophysical model
 
Dear Foamers,


I'm making my own thermophysical model. For that reason I wrote some functions I want to you use to calculate the different properties (in thermoI.H, and the respective rho*I.H, transport*I.H, thermo*I.H files). I include the header-file declaring all my functions in "thermoI.H", otherwise the compilation fails, since my functions are not defined.



The compilation of libspecie works w/o problems, but when I try to compile libfluidThermophysicalModels (in the "basic" folder), I get compiler errors telling me, that my functions are multiple defined, e.g. a small fraction of the error message:


Code:

Make/linux64GccDPInt32Opt/rhoThermo/rhoThermos.o: In function `PN_sSCByPT(double, double)':
rhoThermos.C:(.text+0x6bce0): multiple definition of `PN_sSCByPT(double, double)'
Make/linux64GccDPInt32Opt/psiThermo/psiThermos.o:psiThermos.C:(.text+0x6bce0): first defined here


These lines occur for all of my functions twice:
- for psiThermos.o & rhoThermos.o
- for psiThermos.o & liquidThermo.o


It seems like the compiler declares the functions several times, since their definitions are called by "thermoI.H". I now tried several options to circumvent that issue, but without success. Does anybody has an idea how to solve that issue?


Sincerely,
stockzahn

Gerry Kan March 24, 2020 09:24

Dear Stockzahn:

It sounds like you might need to implement include guards to your header file, so that all the objects / functions only get declared once during compile.

You should surround the contents of your header file with the following lines:

Code:

#ifndef __YOUR_HEADER_NAME__
#define __YOUR_HEADER_NAME__

  // contents of your original header file goes here

#endif

Hope that helps, Gerry.

stockzahn March 24, 2020 11:10

Dear Gerry,


thanks for the fast response, unfortunately that didn't work.


stockzahn


EDIT: I solved it: obviously a very beginner's mistake: I tested the functions in a different program, for which in included all C-files in the header files. This was the problem, I just copied all files into the inlude-folder and deleted the #include-commands in the header-files. But thanks for the hint with the include guards! That will be advantegeous in the future.


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