ITADN

[BUG]: cmake: pybind11::embed target doesn't link to Python libs if find_package(Python) has been called previously

#6063Openantonio-rojas 创建于 2026-05-14
triage
A
antonio-rojascommented
### Required prerequisites - [x] Make sure you've read the [documentation](https://pybind11.readthedocs.io). Your issue may be addressed there. - [x] Search the [issue tracker](https://github.com/pybind/pybind11/issues) and [Discussions](https:/pybind/pybind11/discussions) to verify that this hasn't already been reported. +1 or comment there if it has. - [x] Consider asking first in the [Gitter chat room](https://gitter.im/pybind/Lobby) or in a [Discussion](https:/pybind/pybind11/discussions/new). ### What version (or hash if on master) of pybind11 are you using? 3.0.4 ### Problem description If `find_package(pybind11)` is called after a previous `find_package(Python)` *without* the development component, then the `pybind11::embed` target is missing a link to the `Python::Python` target. Test case: ``` cmake_minimum_required(VERSION 3.5) include(CMakePrintHelpers) find_package(Python COMPONENTS Interpreter) find_package(pybind11 REQUIRED) cmake_print_properties( TARGETS pybind11::embed PROPERTIES INTERFACE_LINK_LIBRARIES ) ``` Output: ``` Properties for TARGET pybind11::embed: pybind11::embed.INTERFACE_LINK_LIBRARIES = "pybind11::pybind11" ``` Note that `Python::Python` is missing. In https://github.com/pybind/pybind11/blob/v3.0.4/tools/pybind11NewTools.cmake#L96 `_Python` is set to `Python` without a check for the `Python::Python` target (which only exists if the Development component has been requested in the `find_package(Python)` call), but then this target is needed in https://github.com/pybind/pybind11/blob/v3.0.4/tools/pybind11NewTools.cmake#L227. The previous `find_package(Python)` may have been issued by some dependency, so this is not always under the project's control. ### Reproducible example code ```text ``` ### Is this a regression? Put the last known working version here if it is. Not a regression
0 条评论