Skip to content

Statically link libpython on MacOS #636

@geofft

Description

@geofft

In #604 we rolled back ./configure --enable-static-libpython-for-interpreter for macOS because it caused link failures with, it seems, symbols for third-party libraries statically linked into libpython, e.g.:

cpython-3.14> ld64.lld: error: undefined symbol: BZ2_bzDecompress
cpython-3.14> ld64.lld: error: undefined symbol: ffi_prep_closure_loc
cpython-3.14> ld64.lld: error: undefined symbol: Tcl_FindExecutable

The patch also failed on Python 3.9 through 3.11 because it conflicted with this other patch:

# Also on macOS, the `python` executable is linked against libraries defined by statically
# linked modules. But those libraries should only get linked into libpython, not the
# executable. This behavior is kinda suspect on all platforms, as it could be adding
# library dependencies that shouldn't need to be there.
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
    if [ "${PYTHON_MAJMIN_VERSION}" = "3.9" ]; then
        patch -p1 -i ${ROOT}/patch-python-link-modules-3.9.patch
    elif [ "${PYTHON_MAJMIN_VERSION}" = "3.10" ]; then
        patch -p1 -i ${ROOT}/patch-python-link-modules-3.10.patch
    else
        patch -p1 -i ${ROOT}/patch-python-link-modules-3.11.patch
    fi
fi

That comment seems extremely relevant to the link failures.

We should turn --enable-static-libpython-for-interpreter back on for macOS builds, and I should understand exactly what that comment means, including investigating whether it makes sense on other platforms.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions