Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: symbol not found in flat namespace (__Py_DECREF_DecRefTotal) #5056

Closed
2 of 3 tasks
DDoS opened this issue Mar 11, 2024 · 2 comments
Closed
2 of 3 tasks

[BUG]: symbol not found in flat namespace (__Py_DECREF_DecRefTotal) #5056

DDoS opened this issue Mar 11, 2024 · 2 comments
Labels
triage New bug, unverified

Comments

@DDoS
Copy link

DDoS commented Mar 11, 2024

Required prerequisites

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

@DDoS DDoS added the triage New bug, unverified label Mar 11, 2024
@bansan85
Copy link

bansan85 commented Apr 3, 2024

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)

@DDoS
Copy link
Author

DDoS commented Apr 3, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New bug, unverified
Projects
None yet
Development

No branches or pull requests

2 participants