pybind / pybind/pybind11

[BUG]: Python_ADD_LIBRARY: target Python::Module not defined

Open
#5,813 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

Required prerequisites
What version (or hash if on master) of pybind11 are you using?

3.0.0

Problem description

When using find_package(Python COMPONENTS Interpreter) before using find_package(pybind11), I get the following error:

CMake Error at /usr/share/cmake-3.28/Modules/FindPython/Support.cmake:4064 (message):
  Python_ADD_LIBRARY: dependent target 'Python::Module' is not defined.

     Did you miss to request COMPONENT 'Development.Module'?
Call Stack (most recent call first):
  /usr/share/cmake-3.28/Modules/FindPython.cmake:635 (__Python_add_library)
  /opt/ros/one/share/pybind11_catkin/cmake/pybind11NewTools.cmake:283 (python_add_library)

Obviously, the first call to find_package(Python) should include the Development component.
However, I don't have control about this find_package call as it occurs in another upstream software package.
IMHO, pybind11 needs to ensure itself that all required components are find_packaged.

This issue is related to #3996, which identified an order dependency of find_package calls too.

Reproducible example code

Is this a regression? Put the last known working version here if it is.

Not a regression

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with pybind11NewTools.cmake around line 283 and trace its python_add_library call alongside CMake's FindPython.cmake and the reported FindPython/Support.cmake error. Reproduce the ordering of find_package(Python COMPONENTS Interpreter) and find_package(pybind11), then verify that the required Python target is available without depending on the upstream package's call order.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, python
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.