|
[Sponsors] |
June 8, 2017, 22:27 |
Understanding of a MakeFile
|
#1 |
New Member
Lieh
Join Date: Mar 2017
Posts: 26
Rep Power: 9 |
Hello
I have got a code, in its main makefile it is like Code:
faceProperties/faceProperties.C faceProperties/faceComp/faceComp.C Solver.C EXE = $(FOAM_USER_APPBIN)/Solver.C Code:
interfaceProperties.C faceComp/aceComp.C LIB = $(FOAM_LIBBIN)/libfaceProperties What was wrong by just putting the sub .C and .H files in the main mother folder and not introducing these sub Make folders and sub .C and .H files? Do I need to run the sub Make files also? or running the main Make file is enough? what does the third line below mean? why is does not have _USER and also it is named as libfaceProperties? what does "lib" in libfaceProperties refer to? Code:
faceProperties.C faceComp/faceComp.C LIB = $(FOAM_LIBBIN)/libfaceProperties |
|
June 9, 2017, 03:40 |
|
#2 | ||||
Senior Member
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 20 |
First things first:
That is not a Makefile. It is the Make/files file from the wmake system, which is derived from make... But it's not actually a Makefile. Quote:
Quote:
If OpenFOAM would do that, it would have (idk?) 500 .C files and 500 .H files in the same directory. You can probably see that this would be absolutely terrible. The same principle applies to your solver, although you could argue that two files more or less does not matter. Quote:
In your case, the .C files of the subdirectory were already added to your main Make/files. Therefore, they will already be compiled, and included into the mentioned EXE: Code:
EXE = $(FOAM_USER_APPBIN)/Solver.C Code:
EXE = $(FOAM_USER_APPBIN)/Solver Now, if we you were to leave these subdirectory .C files out, then they wouldn't be compiled, nor added to the Solver executable. Therefore, the Solver executable will have a smaller size... But code would be missing, so your solver cannot execute. Your Solver will then search for a dynamic library that contains the code in $FOAM_USER_LIBBIN or $FOAM_LIBBIN. However, it will only do so if that library was included in Make/options. (If it is not, I think that the code will not compile in the first place.) Your subdirectory's Make/files make such a library. Read on: Quote:
It is a (dynamic) library. All dynamic libraries start their names with "lib": that is mandatory. For instance, the library fooBar will be written to the file "libfooBar.so." Any executable that requires fooBar will look for "libfooBar.so" in all directories present in your LD_LIBRARY_PATH environmental variable. A dynamic library permits you to compile this code independent of your solver. Also, you'll be able to use that library's code for multiple solvers. It also becomes easier to inject new custom code, as you don't have to re-compile everything: it is dynamically linked at runtime. Imagine if OpenFOAM was monolithic instead... Then any kind of change would have required to recompile virtually everything! That would take hours for the smallest change... That's a lot less maintainable. In other words: Your main directory's Make/files does already compile all code. Calling wmake on the subdirectory would create a dynamic library of that code, but it wouldn't be used for your solver, as your solver executable already includes that code within itself. Usually, you'd want to dynamically link such code... If it is code that can be used by multiple executables(/solvers). That is done by the subdirectory's Make/files with its "LIB=" line. If this code is very specific to your solver, you might as well include the code directory into the executable, which your main Make/files currently does. |
|||||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How can I add my cpp and hpp files to the makefile? | Yminjo | SU2 | 2 | December 9, 2016 08:16 |
Adding PETSc to my userdefined Makefile | Mahnaz | Main CFD Forum | 9 | January 26, 2014 13:51 |
Understanding pimpleFoam convergence criterion | Nucleophobe | OpenFOAM Running, Solving & CFD | 0 | March 13, 2013 18:46 |
Makefile for f90 under unix | Jinwon | Main CFD Forum | 1 | September 22, 2007 05:10 |
about making makefile | JunseokKim | Main CFD Forum | 1 | May 16, 2001 21:39 |