[BUG]: 'Unknown CMake command "python3_add_library" in pybind11NewTools.cmake
Open
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
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
Problem description
Attempting to build throws an error in tools/pybind11NewTools.cmake throws the following error:
Unknown CMake command "python3_add_library".
Adding find_package (Python3 COMPONENTS Interpreter Development) fixes it.

Reproducible example code
src/cmakelists.txt
configure_file(${CMAKE_SOURCE_DIR}/third_party/pybind11/CMakeLists.txt ${CMAKE_BINARY_DIR}/external-projects/pybind11/CMakeLists.txt)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/external-projects/pybind11"
)
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/external-projects/pybind11"
)
# Add pybind11 makefile
add_subdirectory("${CMAKE_BINARY_DIR}/third_party/pybind11"
"${CMAKE_BINARY_DIR}/third_party/pybind11"
EXCLUDE_FROM_ALL
)
set(PYBIND11_CPP_STANDARD -std=c++11)
# Force Pybind11 not to share resources with other pybind modules.
# With this definition we force the ABI version to be unique and not risk crashes on different modules.
# (workaround for RS5-10582; see also https://github.com/pybind/pybind11/issues/2898)
add_definitions(-DPYBIND11_COMPILER_TYPE="_librs_abi")
include_directories(${CMAKE_BINARY_DIR}/third_party/pybind11/include)
pybind11_add_module(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES} ${PYBIND_FILES})
/third_party/pybind11/
# minimum required cmake version: 3.1.0
cmake_minimum_required(VERSION 3.1.0)
project(pybind11-download NONE)
include(ExternalProject)
ExternalProject_Add(
pybind11
PREFIX .
GIT_REPOSITORY "https://github.com/pybind/pybind11.git"
GIT_TAG "914c06fb252b6cc3727d0eedab6736e88a3fcb01" # 2.9.2
SOURCE_DIR "${CMAKE_BINARY_DIR}/third_party/pybind11"
# Override default steps with no action, we just want the clone step.
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in tools/pybind11NewTools.cmake and reproduce the configure/build flow shown in the issue, checking how Python3 is discovered before python3_add_library is used. Done means the reported project configures without the unknown-command error and the existing pybind11 module build proceeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100