Skip to content

dynamicCode compiler options get overwritten

Summary

When using scalarCodedSource with custom libraries compiler options supplied via codeOptions field get overwritten. The same problem probably exists with codeLibs, but due to this error I could never get to the linking stage of the compilation.

Steps to reproduce

git clone https://develop.openfoam.com/Development/openfoam.git --branch master
cd openfoam/tutorials/heatTransfer/chtMultiRegionSimpleFoam/jouleHeatingSolid
cat > constant/solid/fvOptions << _EOF_
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2206                                  |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
FoamFile
{
    version         2;
    format          ascii;
    class           dictionary;
    object          fvOptions;
}

customHeatSource
{
    type            scalarCodedSource;
    name            heatSource;
    active          true;
    scalarCodedSourceCoeffs
    {
        selectionMode   all;
        fields          ( h );
        codeInclude     #{ #include <mpi.h> #};
        codeOptions     #{ #};
        codeLibs        #{ #};
        codeCorrect     #{ #};
        codeAddSupRho   #{ Pout << "hello!" << std::endl #};
        codeAddSup      #{ #};
        codeConstrain   #{ #};
    }
}
_EOF_
./Allclean
./Allrun.pre
chtMultiRegionSimpleFoam

Observe compilation error mpi.h: No such file or directory.

Add output of pkg-config --cflags mpi-cxx and pkg-config --libs mpi-cxx to codeOptions and codeLibs of constant/solid/fvOptions respectively (sorry, I don't know how to set verbatim fields from foamDictionary). On my machine, edited lines look like this:

codeOptions     #{ -pthread -I/usr/lib/x86_64-linux-gnu/openmpi/include -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi #};
codeLibs        #{ -L/usr/lib/x86_64-linux-gnu/openmpi/lib -lmpi_cxx -lmpi #};

Run compilation again and catch compilation commands using bear.

rm -rf dynamicCode
./Allclean
./Allrun.pre
bear -- chtMultiRegionSimpleFoam

Observe the same compilation error mpi.h: No such file or directory.

Issue command

cat dynamicCode/heatSource/Make/options

and observe that codeOption paths are the same as in fvOptions file

Issue command

cat compile_commands.json

and observe that x86_64-linux-gnu strings in compilation commands were replaced by x86_64-1-gnu.

Example case

See Steps to reproduce

What is the current bug behaviour?

User supplied compiler options are modified before compilation

What is the expected correct behavior?

User supplied compiler options are NOT modified before compilation

Relevant logs and/or images

Environment information

  • OpenFOAM version : master 76d719d1
  • Operating system : GNU Linux Debian bookworm
  • Hardware info : x86-64
  • Compiler : gcc (Debian 11.3.0-4) 11.3.0

Possible fixes