Skip to content

Dynamic linker environment variables setup on Darwin

Summary

Folder existence check was introduced on Darwin in _foamAddLib function. The function fails, when multiple folders separated by colon are passed as an argument. Due to this bug FOAM_USER_LIBBIN and FOAM_SITE_LIBBIN are not added to DYLD_LIBRARY_PATH.

Steps to reproduce

  1. Setup OpenFOAM(R) environment.
  2. Look at DYLD_LIBRARY_PATH: neither FOAM_USER_LIBBIN, nor FOAM_SITE_LIBBIN are there.

What is the current bug behaviour?

FOAM_USER_LIBBIN and FOAM_SITE_LIBBIN are missing from DYLD_LIBRARY_PATH, so user-compiled libraries are not found by dynamic linker.

What is the expected correct behavior?

Libraries located in FOAM_USER_LIBBIN or FOAM_SITE_LIBBIN should be found by dynamic linker.

Environment information

  • OpenFOAM version : v2312
  • Operating system : macOS
  • Compiler : clang

Possible fixes

There are two possible approaches to fix the issue.

  1. Remove -e check from _foamAddLib function. I.e. change this (etc/config.sh/functions:92)

    _foamAddLib()
    {
        case "$1" in (/?*)
        if [ -e "$1" ]
        then
            export FOAM_LD_LIBRARY_PATH="${1}${FOAM_LD_LIBRARY_PATH:+:}${FOAM_LD_LIBRARY_PATH}"
            export DYLD_LIBRARY_PATH="$FOAM_LD_LIBRARY_PATH"
        fi
        esac
    }

    to

    _foamAddLib()
    {
        case "$1" in (/?*)
            export FOAM_LD_LIBRARY_PATH="${1}${FOAM_LD_LIBRARY_PATH:+:}${FOAM_LD_LIBRARY_PATH}"
            export DYLD_LIBRARY_PATH="$FOAM_LD_LIBRARY_PATH"
        esac
    }

    The same should be applied to csh functions.

  2. Do not pass multiple folders to _foamAddLib function, effectively splitting single function call to multiple. I.e. instead of this (etc/config.sh/setup:233):

    _foamAddLib  "$FOAM_USER_LIBBIN:$FOAM_SITE_LIBBIN"

    use this

    _foamAddLib "$FOAM_SITE_LIBBIN"
    _foamAddLib "$FOAM_USER_LIBBIN"  # User library folder has higher priority

    grep -r in etc folder shows, that this line is a single invocation of _foamAddLib with multi-folder argument. So, maybe, this approach is easier.