Skip to content

fix(libpython): link libintl so _localemodule resolves on macOS#450

Open
hjmjohnson wants to merge 1 commit into
python-cmake-buildsystem:masterfrom
hjmjohnson:fix/link-libintl-localemodule-macos
Open

fix(libpython): link libintl so _localemodule resolves on macOS#450
hjmjohnson wants to merge 1 commit into
python-cmake-buildsystem:masterfrom
hjmjohnson:fix/link-libintl-localemodule-macos

Conversation

@hjmjohnson

Copy link
Copy Markdown

On macOS, every target linking libpython (including the _freeze_importlib bootstrap tool) fails with undefined _libintl_bindtextdomain / _libintl_dcgettext / _libintl_bind_textdomain_codeset symbols when a separate libintl (gettext) is present.

_localemodule.c calls the libintl_* functions whenever HAVE_LIBINTL_H is defined, but HAVE_LIBINTL (the found intl library) was only added to CMAKE_REQUIRED_LIBRARIES for configure checks — never to the libpython link libraries. This mirrors CPython's own configure, which appends -lintl to LIBS. On glibc the gettext functions live in libc, so HAVE_LIBINTL is unset and this is a no-op.

Fix: append HAVE_LIBINTL to LIBPYTHON_TARGET_LIBRARIES when found, mirroring the adjacent HAVE_LIBDL handling.

Reproduction / validation

Surfaced building CPython 3.12.10 on arm64 macOS with a conda-forge gettext on the prefix path (via 3D Slicer's SuperBuild). Before: _freeze_importlib link fails with the undefined _libintl_* symbols. After: _freeze_importlib, libpython3.12.dylib, and the python executable all link and build to completion (397/397).

_localemodule.c calls libintl_* (bindtextdomain, dcgettext, ...) when
HAVE_LIBINTL_H is defined. HAVE_LIBINTL (the intl library) was added only
to CMAKE_REQUIRED_LIBRARIES for configure checks, never to the libpython
link libraries. On platforms where libintl is a separate library (e.g.
macOS gettext), every target linking libpython -- including the
_freeze_importlib bootstrap tool -- then fails with undefined _libintl_*
symbols. glibc keeps these functions in libc, so HAVE_LIBINTL is unset
there and this is a no-op.

Append HAVE_LIBINTL to LIBPYTHON_TARGET_LIBRARIES when found, mirroring the
existing HAVE_LIBDL handling and CPython configure's `LIBS += -lintl`.
@hjmjohnson
hjmjohnson marked this pull request as ready for review July 5, 2026 12:58
@hjmjohnson

Copy link
Copy Markdown
Author

@thewtex This fix was needed to get Slicer built on mac using a pixi environment set of compilers.

@thewtex thewtex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me

@thewtex

thewtex commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

ping @jcfr

@hjmjohnson

Copy link
Copy Markdown
Author

ping @jamesobutler Do you have merge capabilities here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants