-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
TLDR
I think the cmake variable PYTHON_IS_DEBUG is not visible inside the scope of the function pybind11_add_module.
What
Trying to create a debug build, using the debug version of Python with cmake:
-DCMAKE_BUILD_TYPE=Debug-DPYTHON_EXECUTABLE=/usr/lib/python3.6-dgb
Build goes fine, but importing the resulting module gives an Import Error about the undefined symbol PyModule_Create2.
From what I have read, this indicates that we are linking correctly against the debug version of Python, but the includes are wrong, since PyModule_Create2 has a different name in the debug version of Python.
Solution?
- is not working as it should.
pybind11/tools/pybind11Tools.cmake
Lines 142 to 147 in 3735249
# Python debug libraries expose slightly different objects # https://docs.python.org/3.6/c-api/intro.html#debugging-builds # https://stackoverflow.com/questions/39161202/how-to-work-around-missing-pymodule-create2-in-amd64-win-python35-d-lib if(PYTHON_IS_DEBUG) target_compile_definitions(${target_name} PRIVATE Py_DEBUG) endif() - I have verified that
PYTHON_IS_DEBUGis set correctly in https://github.com/pybind/pybind11/blob/master/tools/FindPythonLibsNew.cmake#L115, and it is also correct inpybind11Tools.cmake(outside the function scope)... - ... but not when the function is called.
I am having trouble understanding cmake's scoping rules. If I set PYTHON_IS_DEBUG in the cmake CACHE it works. I cannot tell whether this is the correct solution though?
Versions
- cmake 3.10.2
- pybind11 2.4.3
- python3.6-dbg
- Ubuntu