[BUG]: symbol not found in flat namespace (__Py_DECREF_DecRefTotal)
DDoS opened this issue · comments
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.
What version (or hash if on master) of pybind11 are you using?
2.11.1
Problem description
I get a single symbol not found issue. I checked that I'm using the same python to compile and run. The only comment I've found that references this error is python/cpython#108562, but it hasn't helped.
EDIT: this is only an issue when creating a debug build.
[py] (main) ! /usr/local/bin/python3.12
Python 3.12.2 (main, Feb 20 2024, 04:30:04) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import py_encre
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(<..>/cadre/build/debug/py/py_encre.cpython-312-darwin.so, 0x0002): symbol not found in flat namespace (__Py_DECREF_DecRefTotal)
//Path to a program.
_Python_EXECUTABLE:INTERNAL=/usr/local/bin/python3.12
//Path to a file.
_Python_INCLUDE_DIR:INTERNAL=/usr/local/opt/python@3.12/Frameworks/Python.framework/Versions/3.12/include/python3.12
//Python Properties
_Python_INTERPRETER_PROPERTIES:INTERNAL=Python;3;12;2;64;;cpython-312-darwin;abi3;/usr/local/opt/python@3.12/Frameworks/Python.framework/Versions/3.12/lib/python3.12;/usr/local/opt/python@3.12/Frameworks/Python.framework/Versions/3.12/lib/python3.12;/usr/local/lib/python3.12/site-packages;/usr/local/lib/python3.12/site-packages
_Python_INTERPRETER_SIGNATURE:INTERNAL=4c035cd690ab226aa15325c7c3748186
//Interpreter reason failure
_Python_Interpreter_REASON_FAILURE:INTERNAL=
//Path to a library.
_Python_LIBRARY_RELEASE:INTERNAL=/usr/local/opt/python@3.12/Frameworks/Python.framework/Versions/3.12/lib/libpython3.12.dylib
I'm on macOS 12.7.3.
Reproducible example code
Basically an empty module. I stripped out all the code.
cmake_minimum_required(VERSION 3.23)
project("encre" LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(Python 3 COMPONENTS Interpreter Development)
find_package(pybind11 CONFIG)
pybind11_add_module(py_encre "src/py_encre.cpp")
#include <pybind11/pybind11.h>
PYBIND11_MODULE(py_encre, m) {
m.doc() = "Python bindings for Encre";
}
Is this a regression? Put the last known working version here if it is.
Not know to be a regression
Did you fixed your problem ?
If you have a debug build, why do you use python3.12 and not python3.12d ?
See https://gitlab.kitware.com/cmake/cmake/-/issues/25764
Can you try:
if(NOT WIN32)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(Python3_FIND_ABI "ON" "ANY" "ANY")
else()
set(Python3_FIND_ABI "OFF" "ANY" "ANY")
endif()
endif()
find_package(
Python3
COMPONENTS Interpreter Development)
find_package(pybind11 CONFIG)
@bansan85 Thanks for the hint. I finally figured out that it's a Vcpkg issue. There's a patch that forces Py_DEBUG
for any CMake debug build, regardless of the Python being linked. Removing the flag fixes it:
get_target_property(pybind11_definitions pybind11::pybind11_headers INTERFACE_COMPILE_DEFINITIONS)
list(FILTER pybind11_definitions EXCLUDE REGEX "Py_DEBUG")
set_property(TARGET pybind11::pybind11_headers PROPERTY INTERFACE_COMPILE_DEFINITIONS ${pybind11_definitions})
There's an open issue to remove the patch, but doing so creates unwanted behaviour in Vcpkg, so maybe it will stay.