WRF-Chem/KPP build stops: “third body expected to be M” in CBM4 species file

William.Hatheway

Well-known member
Hi all — I’m seeing a reproducible WRF-Chem/KPP build stop that looks like an internal consistency issue in the CBM4 mechanism files


During a WRF-Chem build (`WRF_CHEM=1`, `WRF_KPP=1`), the `chem/KPP/compile_wkc` step iterates over mechanisms and exits with:

Bash:
> `ERROR: variable name for third body in KPP species file is expected to be M, but was not found in cbm4 species file`

It occurs while processing:


Code:
chem/KPP/mechanisms/cbm4/cbm4.spc

Other mechanisms in the same tree define the third-body species explicitly as `M` (commonly annotated as “third body”), and the coupler logic appears to require that exact symbol name. In my case, CBM4’s `cbm4.spc` does not contain `M`, so the mechanism validation fails and the overall build stops—even if CBM4 is not the mechanism I intend to run.

This suggests a mismatch between:

* the WKC/KPP expectations (“third body must be named `M`”), and
* the shipped CBM4 species file content (missing/renamed third-body definition).

Can NCAR/WRF-Chem maintainers confirm whether:

1. `cbm4.spc` is supposed to include a third-body species named `M`, and/or
2. `compile_wkc` should be more flexible for CBM4 naming, and/or
3. this is a packaging/version regression specific to certain releases?
 
Last edited:
Hi all — I’m seeing a reproducible WRF-Chem/KPP build stop that looks like an internal consistency issue in the CBM4 mechanism files


During a WRF-Chem build (`WRF_CHEM=1`, `WRF_KPP=1`), the `chem/KPP/compile_wkc` step iterates over mechanisms and exits with:

Bash:
> `ERROR: variable name for third body in KPP species file is expected to be M, but was not found in cbm4 species file`

It occurs while processing:


Code:
chem/KPP/mechanisms/cbm4/cbm4.spc

Other mechanisms in the same tree define the third-body species explicitly as `M` (commonly annotated as “third body”), and the coupler logic appears to require that exact symbol name. In my case, CBM4’s `cbm4.spc` does not contain `M`, so the mechanism validation fails and the overall build stops—even if CBM4 is not the mechanism I intend to run.

This suggests a mismatch between:

* the WKC/KPP expectations (“third body must be named `M`”), and
* the shipped CBM4 species file content (missing/renamed third-body definition).

Can NCAR/WRF-Chem maintainers confirm whether:

1. `cbm4.spc` is supposed to include a third-body species named `M`, and/or
2. `compile_wkc` should be more flexible for CBM4 naming, and/or
3. this is a packaging/version regression specific to certain releases?
Any update one this?
 
Hi all — I’m seeing a reproducible WRF-Chem/KPP build stop that looks like an internal consistency issue in the CBM4 mechanism files


During a WRF-Chem build (`WRF_CHEM=1`, `WRF_KPP=1`), the `chem/KPP/compile_wkc` step iterates over mechanisms and exits with:

Bash:
> `ERROR: variable name for third body in KPP species file is expected to be M, but was not found in cbm4 species file`

It occurs while processing:


Code:
chem/KPP/mechanisms/cbm4/cbm4.spc

Other mechanisms in the same tree define the third-body species explicitly as `M` (commonly annotated as “third body”), and the coupler logic appears to require that exact symbol name. In my case, CBM4’s `cbm4.spc` does not contain `M`, so the mechanism validation fails and the overall build stops—even if CBM4 is not the mechanism I intend to run.

This suggests a mismatch between:

* the WKC/KPP expectations (“third body must be named `M`”), and
* the shipped CBM4 species file content (missing/renamed third-body definition).

Can NCAR/WRF-Chem maintainers confirm whether:

1. `cbm4.spc` is supposed to include a third-body species named `M`, and/or
2. `compile_wkc` should be more flexible for CBM4 naming, and/or
3. this is a packaging/version regression specific to certain releases?
seems to be a flex lib issue utilizing the flex apt package. If you install flex from source locally on your computer and point it to that it resolves the issue.

I would recommend for WRF 4.8.0 coming out soon that there be an optional instruction guide for installing flex package as part of the WRF library files.
 
seems to be a flex lib issue utilizing the flex apt package. If you install flex from source locally on your computer and point it to that it resolves the issue.

I would recommend for WRF 4.8.0 coming out soon that there be an optional instruction guide for installing flex package as part of the WRF library files.
Hi @William.Hatheway,

which version of flex do you recommend using (and compiling) for the latest WRF-chem release?
I'm using INTEL OneAPI (ifx/icx).
 
Hi @William.Hatheway,

which version of flex do you recommend using (and compiling) for the latest WRF-chem release?
I'm using INTEL OneAPI (ifx/icx).
Bash:
build_flex_from_source() {
        echo "[flex] Building flex 2.6.4 from source..."

        # Clean old custom installs in WRF tree
        rm -rf "${WRF_FOLDER}/Libs/flex-2.6.4" 2>/dev/null || true
        rm -rf /tmp/flex-2.6.4 /tmp/flex-2.6.4.tar.gz 2>/dev/null || true

        # Remove typical /usr/local flex files (not managed by apt/dnf)
        echo "$PASSWD" | sudo -S bash -c '
        rm -f /usr/local/bin/flex
        rm -f /usr/local/lib/libfl.a /usr/local/lib/libfl.so /usr/local/lib/libfl.so.*
        rm -f /usr/local/lib64/libfl.a /usr/local/lib64/libfl.so /usr/local/lib64/libfl.so.*
        rm -f /usr/local/include/FlexLexer.h
        '

        cd /tmp || exit 1
        wget -q https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz
        if [ ! -f flex-2.6.4.tar.gz ]; then
            echo "[flex] ERROR: failed to download flex-2.6.4.tar.gz"
            exit 1
        fi

        tar -xzf flex-2.6.4.tar.gz
        cd flex-2.6.4 || exit 1

        # IMPORTANT: avoid polluting flex build with WRF's exported flags
        unset CPPFLAGS CFLAGS CXXFLAGS FCFLAGS LDFLAGS LIBS

        ./configure --prefix=/usr --enable-shared 2>&1 | tee "${WRF_FOLDER}/Downloads/flex.configure.log"
        make -j"$(nproc 2>/dev/null || echo 2)" 2>&1 | tee "${WRF_FOLDER}/Downloads/flex.make.log"
        echo "$PASSWD" | sudo -S make install
        echo "$PASSWD" | sudo -S ldconfig || true

        # Verify after install
        if ! command -v flex >/dev/null 2>&1; then
            echo "[flex] ERROR: flex still not found after source install."
            exit 1
        fi
        if ! (ldconfig -p 2>/dev/null | grep -q 'libfl\.so\.2' ||
            find /usr /lib /usr/local -type f -name 'libfl.so.2*' 2>/dev/null | grep -q .); then
            echo "[flex] ERROR: libfl.so.2 still not found after source install."
            exit 1
        fi

        echo "[flex] Source build complete: $(flex --version 2>/dev/null || echo flex)"
    }

that's how i do it in my installation codes
 
Thank you!
Bash:
build_flex_from_source() {
        echo "[flex] Building flex 2.6.4 from source..."

        # Clean old custom installs in WRF tree
        rm -rf "${WRF_FOLDER}/Libs/flex-2.6.4" 2>/dev/null || true
        rm -rf /tmp/flex-2.6.4 /tmp/flex-2.6.4.tar.gz 2>/dev/null || true

        # Remove typical /usr/local flex files (not managed by apt/dnf)
        echo "$PASSWD" | sudo -S bash -c '
        rm -f /usr/local/bin/flex
        rm -f /usr/local/lib/libfl.a /usr/local/lib/libfl.so /usr/local/lib/libfl.so.*
        rm -f /usr/local/lib64/libfl.a /usr/local/lib64/libfl.so /usr/local/lib64/libfl.so.*
        rm -f /usr/local/include/FlexLexer.h
        '

        cd /tmp || exit 1
        wget -q https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz
        if [ ! -f flex-2.6.4.tar.gz ]; then
            echo "[flex] ERROR: failed to download flex-2.6.4.tar.gz"
            exit 1
        fi

        tar -xzf flex-2.6.4.tar.gz
        cd flex-2.6.4 || exit 1

        # IMPORTANT: avoid polluting flex build with WRF's exported flags
        unset CPPFLAGS CFLAGS CXXFLAGS FCFLAGS LDFLAGS LIBS

        ./configure --prefix=/usr --enable-shared 2>&1 | tee "${WRF_FOLDER}/Downloads/flex.configure.log"
        make -j"$(nproc 2>/dev/null || echo 2)" 2>&1 | tee "${WRF_FOLDER}/Downloads/flex.make.log"
        echo "$PASSWD" | sudo -S make install
        echo "$PASSWD" | sudo -S ldconfig || true

        # Verify after install
        if ! command -v flex >/dev/null 2>&1; then
            echo "[flex] ERROR: flex still not found after source install."
            exit 1
        fi
        if ! (ldconfig -p 2>/dev/null | grep -q 'libfl\.so\.2' ||
            find /usr /lib /usr/local -type f -name 'libfl.so.2*' 2>/dev/null | grep -q .); then
            echo "[flex] ERROR: libfl.so.2 still not found after source install."
            exit 1
        fi

        echo "[flex] Source build complete: $(flex --version 2>/dev/null || echo flex)"
    }

that's how i do it in my installation codes

!
 
Back
Top