Skip to content

Commit daf9053

Browse files
committed
fix(cmake): compile the precompiled library with the interpreter ABI macros
pybind11::pybind11 only carries headers; Py_GIL_DISABLED lives on Python::Module via pybind11::module. Without it the library is ABI-mismatched on free-threaded builds, and on Windows the pyconfig.h autolink pragma in its objects requests pythonXY.lib instead of pythonXYt.lib. Assisted-by: ClaudeCode:claude-fable-5
1 parent 2c17718 commit daf9053

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

tools/pybind11Common.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,13 @@ function(pybind11_precompile)
512512
add_library(pybind11_precompiled STATIC EXCLUDE_FROM_ALL ${_pybind11_precompile_sources})
513513
add_library(pybind11::precompiled ALIAS pybind11_precompiled)
514514
target_compile_definitions(pybind11_precompiled PUBLIC PYBIND11_PRECOMPILED)
515+
# pybind11::module (not just pybind11::pybind11): the library must compile with the
516+
# interpreter's ABI macros (e.g. Py_GIL_DISABLED, which FindPython attaches to
517+
# Python::Module); on free-threaded Windows they select the correct autolink library.
515518
target_link_libraries(
516519
pybind11_precompiled
517520
PUBLIC pybind11::headers
518-
PRIVATE pybind11::pybind11)
521+
PRIVATE pybind11::module)
519522
set_target_properties(pybind11_precompiled PROPERTIES POSITION_INDEPENDENT_CODE ON)
520523
_pybind11_default_hidden_visibility(pybind11_precompiled)
521524
if(NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN)

0 commit comments

Comments
 (0)