Skip to content

Commit 105eb6c

Browse files
ax3lwjakob
authored andcommitted
Debug Builds: -DPy_DEBUG (#1438)
builds against a python debug library were unreliable and could lead to symbol errors during linking. Setting the `Py_DEBUG` define is necessary when linking against a debug build: https://stackoverflow.com/questions/39161202/how-to-work-around-missing-pymodule-create2-in-amd64-win-python35-d-lib https://docs.python.org/2/c-api/intro.html#debugging-builds https://docs.python.org/3.6/c-api/intro.html#debugging-builds
1 parent 64893d4 commit 105eb6c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tools/pybind11Tools.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ function(pybind11_add_module target_name)
135135
PRIVATE ${pybind11_INCLUDE_DIR} # from pybind11Config
136136
PRIVATE ${PYTHON_INCLUDE_DIRS})
137137

138+
# Python debug libraries expose slightly different objects
139+
# https://docs.python.org/3.6/c-api/intro.html#debugging-builds
140+
# https://stackoverflow.com/questions/39161202/how-to-work-around-missing-pymodule-create2-in-amd64-win-python35-d-lib
141+
if(PYTHON_IS_DEBUG)
142+
target_compile_definitions(${target_name} PRIVATE Py_DEBUG)
143+
endif()
144+
138145
# The prefix and extension are provided by FindPythonLibsNew.cmake
139146
set_target_properties(${target_name} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}")
140147
set_target_properties(${target_name} PROPERTIES SUFFIX "${PYTHON_MODULE_EXTENSION}")

0 commit comments

Comments
 (0)