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

undefined reference to `PyCMethod_New' #3115

Open
EnziinSystem opened this issue Jul 15, 2021 · 7 comments
Open

undefined reference to `PyCMethod_New' #3115

EnziinSystem opened this issue Jul 15, 2021 · 7 comments

Comments

@EnziinSystem
Copy link

My environment:

Ubuntu 20.04
Python 3.8.10

When I run compile a program use pybind11, it raise a error:

/usr/bin/ld: ../scripting/libscripting.a(python_scripting.cpp.o): in function `pybind11::cpp_function::initialize_generic(std::unique_ptr<pybind11::detail::function_record, pybind11::cpp_function::InitializingFunctionRecordDeleter>&&, char const*, std::type_info const* const*, unsigned long)':
/home/../ubuntu/kicad/thirdparty/pybind11/include/pybind11/pybind11.h:415: undefined reference to `PyCMethod_New'
collect2: error: ld returned 1 exit status
make[2]: *** [bitmap2component/CMakeFiles/bitmap2component.dir/build.make:191: bitmap2component/bitmap2component] Error 1
make[1]: *** [CMakeFiles/Makefile2:3754: bitmap2component/CMakeFiles/bitmap2component.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
@jiwaszki
Copy link
Contributor

Without minimal example it is hard to tell, but I think that linking is source of your problem.

Look at these two stacks:

@Keepmoving-ZXY
Copy link

The same problem in my project, and I am working on a simple cast to reproduct this error.

@G-Pereira
Copy link

What was the issue @Keepmoving-ZXY ? I need to fix it in mine as well

@Keepmoving-ZXY
Copy link

According to my memory, I solve this problem by changing another version of python.

@G-Pereira
Copy link

That and updating from Ubuntu 20.04 to 22.04, and updating pyside fixed it for me as well. Here was my changes (I did not test which was the culprit):

opulo-inc/lumenpnp@7d21ffd

@NumbNutN
Copy link

NumbNutN commented Feb 2, 2024

Hi, I've solve the problem by update my Python interpreter version to 3.9.18. There's definitely no symbol definition for PyCMethod_New in libpython3.8.so. But I can find it in libpython3.9.so

$ readelf -s lib/libpython3.9.so | grep "PyCMethod"
   489: 0000000000121070   460 FUNC    GLOBAL DEFAULT   11 PyCMethod_New
  1921: 0000000000365ac0   408 OBJECT  GLOBAL DEFAULT   21 PyCMethod_Type
   443: 00000000000696d4   103 FUNC    LOCAL  DEFAULT   11 PyCMethod_New.cold
 36122: 0000000000121070   460 FUNC    GLOBAL DEFAULT   11 PyCMethod_New
 37245: 0000000000365ac0   408 OBJECT  GLOBAL DEFAULT   21 PyCMethod_Type

Notice PyCMethod_New is part of the stable ABI in Python Standard Library since version 3.9.
Python Doc - PyCMethod_New

@roastduck
Copy link

roastduck commented Jul 26, 2024

PyCMethod_New was added in Python 3.9 (https://docs.python.org/3/c-api/structures.html#c.PyCMethod_New), so it is definately not found in Python 3.8. Does that mean pybind11 requires Python >= 3.9?

In my case, the problem turned out to be that I used the Python_FIND_STRATEGY=VERSION mode of FindPython in CMake. In this mode. This is the default mode of my CMake version.

In this mode, CMake will try to find the latest version of Python, even if it is not the first Python in your path. In this case, you will end up including headers from a newer Python whiling executing an older Python, and the older Python cannot link against symbols from the newer header. Setting Python_FIND_STRATEGY=LOCATION solves the problem.

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

No branches or pull requests

6 participants