pybind11
pybind11 copied to clipboard
undefined reference to `PyCMethod_New'
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....
Without minimal example it is hard to tell, but I think that linking is source of your problem.
Look at these two stacks:
- https://stackoverflow.com/a/61085569
- https://stackoverflow.com/questions/27672572/embedding-python-in-c-linking-fails-with-undefined-reference-to-py-initialize
The same problem in my project, and I am working on a simple cast to reproduct this error.
What was the issue @Keepmoving-ZXY ? I need to fix it in mine as well
According to my memory, I solve this problem by changing another version of python.
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):
https://github.com/opulo-inc/lumenpnp/commit/7d21ffdd5ba38b47300d0af594ac255632f6c074
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