[Python-apps-team] Bug#941004: cython3: gcc/ld return "undefined reference" compiling cpp generated with cython3
Antonio
antdev66 at gmail.com
Mon Sep 23 11:23:09 BST 2019
Package: cython3
Version: 0.29.2-2
Severity: important
Dear maintainer,
I recently discovered that compiling a python3 source with cython +
gcc fails by returning errors of the "undefined reference" type,
relative to the linker that does not seem to be able to find
references within the python library.
For example:
# -- created simple program --
$ cat testfile.py
#!/usr/bin/env python3
print("TEST")
# -- test from interpreter (version 3.7.4+) --
$ python3.7 testfile.py
TEST
# -- source creation with cython (version 0.29.2) --
$ cython3 -3 --embed --cplus testfile.py -o testfile.cpp
# -- check cpp file creation --
$ ls -ll a.*
-rw-r--r-- 1 root root 104184 set 23 11:51 testfile.cpp
-rwxr-xr-x 1 root shared 38 set 23 11:50 testfile.py
# -- compilation --
$ g++ -fno-pie -no-pie -O3 -I /usr/include/python3.7 -L
/usr/lib/python3.7/config-3.7m-x86_64-linux-gnu -l python3.7
testfile.cpp -o a
# -- errors returned --
/usr/bin/ld: /tmp/user/0/ccJik3VR.o: in function
`__Pyx_copy_spec_to_module(_object*, _object*, char const*, char const*, int)':
testfile.cpp:(.text.unlikely+0x7a): undefined reference to
`PyObject_GetAttrString'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x88): undefined reference
to `_Py_NoneStruct'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xa0): undefined reference
to `PyDict_SetItemString'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xbc): undefined reference
to `PyExc_AttributeError'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xc5): undefined reference
to `PyErr_ExceptionMatches'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xce): undefined reference
to `PyErr_Clear'
/usr/bin/ld: /tmp/user/0/ccJik3VR.o: in function
`__pyx_pymod_create(_object*, PyModuleDef*)':
testfile.cpp:(.text.unlikely+0xed): undefined reference to
`PyThreadState_Get' /usr/bin/ld: testfile.cpp:(.text.unlikely+0xf6):
undefined reference to `PyInterpreterState_GetID'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x11d): undefined reference
to `PyExc_ImportError'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x127): undefined reference
to `PyErr_SetString'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x151): undefined reference
to `PyObject_GetAttrString'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x161): undefined reference
to `PyModule_NewObject'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x182): undefined reference
to `PyModule_GetDict'
/usr/bin/ld: /tmp/user/0/ccJik3VR.o: in function `__pyx_pymod_exec_a(_object*)':
testfile.cpp:(.text.unlikely+0x25a): undefined reference to `PyExc_RuntimeError'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x264): undefined reference
to `PyErr_SetString'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x28d): undefined reference
to `PyOS_snprintf'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x292): undefined reference
to `Py_GetVersion'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x2ab): undefined reference
to `PyOS_snprintf'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x2e5): undefined reference
to `PyOS_snprintf'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x2f6): undefined reference
to `PyErr_WarnEx'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x325): undefined reference
to `PyTuple_New'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x361): undefined reference
to `PyBytes_FromStringAndSize'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x39d): undefined reference
to `PyUnicode_FromStringAndSize'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x3d9): undefined reference
to `PyModule_GetDict'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x416): undefined reference
to `PyImport_AddModule'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x450): undefined reference
to `PyImport_AddModule'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x498): undefined reference
to `PyObject_SetAttrString'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x4e4): undefined reference
to `PyUnicode_InternFromString'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x502): undefined reference
to `PyUnicode_Decode'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x50d): undefined reference
to `PyUnicode_FromStringAndSize'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x520): undefined reference
to `PyBytes_FromStringAndSize'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x538): undefined reference
to `PyObject_Hash'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x571): undefined reference
to `PyObject_SetAttr'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x5cd): undefined reference
to `_PyThreadState_UncheckedGet'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x616): undefined reference
to `_PyObject_GetDictPtr'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x64e): undefined reference
to `_PyDict_GetItem_KnownHash'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x692): undefined reference
to `PyObject_Not'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x69d): undefined reference
to `_Py_FalseStruct'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x6a4): undefined reference
to `_Py_TrueStruct'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x6be): undefined reference
to `PyErr_Clear'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x6d8): undefined reference
to `_Py_FalseStruct'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x6e0): undefined reference
to `PyObject_SetAttr'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x6e9): undefined reference
to `_Py_FalseStruct'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x6f7): undefined reference
to `_Py_TrueStruct'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x701): undefined reference
to `PyObject_Not'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x7c1): undefined reference
to `PyUnicode_FromString'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x7eb): undefined reference
to `PyUnicode_FromFormat'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x7fa): undefined reference
to `PyUnicode_FromString'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x831): undefined reference
to `PyCode_New'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x887): undefined reference
to `PyMem_Malloc'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x90f): undefined reference
to `PyMem_Realloc'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x977): undefined reference
to `PyFrame_New'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x98a): undefined reference
to `PyTraceBack_Here'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x9c5): undefined reference
to `PyErr_Occurred'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x9d1): undefined reference
to `PyExc_ImportError'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0x9db): undefined reference
to `PyErr_SetString'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xa40): undefined reference
to `PyImport_GetModuleDict'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xa79): undefined reference
to `PyDict_GetItemString'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xa92): undefined reference
to `PyDict_SetItemString'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xadf): undefined reference
to `PyExc_NameError'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xaee): undefined reference
to `PyErr_Format'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xb31): undefined reference
to `PyTuple_Pack'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xb89): undefined reference
to `PyObject_Call'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xb9f): undefined reference
to `PyThreadState_Get'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xbab): undefined reference
to `_Py_CheckRecursionLimit'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xbc2): undefined reference
to `PyThreadState_Get'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xbd1): undefined reference
to `_Py_CheckRecursionLimit'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xbed): undefined reference
to `_Py_CheckRecursiveCall'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xbfc): undefined reference
to `PyThreadState_Get'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xc0a): undefined reference
to `PyErr_Occurred'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xc16): undefined reference
to `PyExc_SystemError'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xc20): undefined reference
to `PyErr_SetString'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xc59): undefined reference
to `PyDict_New'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xc9b): undefined reference
to `PyDict_SetItem'
/usr/bin/ld: /tmp/user/0/ccJik3VR.o: in function `__Pyx_main(int,
wchar_t**) [clone .part.0]':
testfile.cpp:(.text.unlikely+0xd37): undefined reference to `PyModule_Type'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xd3e): undefined reference
to `PyModule_Type'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xd43): undefined reference
to `PyType_IsSubtype'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xd51): undefined reference
to `PyUnicode_FromString'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xd61): undefined reference
to `PyModule_NewObject'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xd88): undefined reference
to `PyModule_ExecDef'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xd91): undefined reference
to `PyErr_Occurred'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xd9b): undefined reference
to `PyErr_Print'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xdbc): undefined reference
to `Py_Finalize'
/usr/bin/ld: /tmp/user/0/ccJik3VR.o: in function `main.cold':
testfile.cpp:(.text.unlikely+0xdd0): undefined reference to `Py_SetProgramName'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xdd5): undefined reference
to `Py_Initialize'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xde1): undefined reference
to `PySys_SetArgv'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xdf4): undefined reference
to `Py_Initialize'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xe29): undefined reference
to `Py_SetProgramName'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xe2e): undefined reference
to `Py_Initialize'
/usr/bin/ld: testfile.cpp:(.text.unlikely+0xe3a): undefined reference
to `PySys_SetArgv'
/usr/bin/ld: /tmp/user/0/ccJik3VR.o: in function
`__Pyx_PyObject_GetAttrStr(_object*, _object*)':
testfile.cpp:(.text.unlikely+0x61): undefined reference to `PyObject_GetAttr'
/usr/bin/ld: /tmp/user/0/ccJik3VR.o: in function `PyInit_a':
testfile.cpp:(.text.unlikely+0xd16): undefined reference to `PyModuleDef_Init'
collect2: error: ld returned 1 exit status
-- but the library exists and contains references indicated as
missing, for example:
/tmp$ objdump -T /usr/lib/x86_64-linux-gnu/libpython3.7m.so|grep
"PyUnicode_FromFormat"
00000000001f7990 g DF .text 0000000000000091 Base PyUnicode_FromFormat
00000000001f6c60 g DF .text 0000000000000d2c Base PyUnicode_FromFormatV
-- why does this procedure no longer work?
Thanks,
Antonio
-- Other details:
$ ls -ll /usr/include/python3.7* -d
drwxr-xr-x 2 root root 4096 lug 15 12:38 /usr/include/python3.7dm
drwxr-xr-x 3 root root 16384 set 8 08:49 /usr/include/python3.7m
lrwxrwxrwx 1 root root 10 ott 21 2018 /usr/include/python3.7 -> python3.7m
$ ls -ll /usr/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7* -d
-rw-r--r-- 1 root root 37815704 set 4 20:42
/usr/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m.a
-rw-r--r-- 1 root root 37207272 set 4 20:42
/usr/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m-pic.a
lrwxrwxrwx 1 root root 41 set 4 10:03
/usr/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m.so ->
../../x86_64-linux-gnu/libpython3.7m.so.1
lrwxrwxrwx 1 root root 41 set 4 10:03
/usr/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7.so ->
../../x86_64-linux-gnu/libpython3.7m.so.1
$ ls -ll /usr/lib/x86_64-linux-gnu/libpython*
lrwxrwxrwx 1 root root 51 set 4 10:19 libpython2.7.a ->
../python2.7/config-x86_64-linux-gnu/libpython2.7.a
lrwxrwxrwx 1 root root 17 set 4 10:19 libpython2.7.so -> libpython2.7.so.1
lrwxrwxrwx 1 root root 19 set 4 10:19 libpython2.7.so.1 ->
libpython2.7.so.1.0
-rw-r--r-- 1 root root 3439088 set 4 20:42 libpython2.7.so.1.0
lrwxrwxrwx 1 root root 18 set 4 10:03 libpython3.7m.so ->
libpython3.7m.so.1
lrwxrwxrwx 1 root root 20 set 4 10:03 libpython3.7m.so.1 ->
libpython3.7m.so.1.0
-rw-r--r-- 1 root root 5018368 set 4 20:42 libpython3.7m.so.1.0
-- System Information:
Debian Release: bullseye/sid
APT prefers unstable
APT policy: (700, 'unstable'), (500, 'stable-updates'), (500,
'stable'), (100, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 5.3.1-custom (SMP w/8 CPU cores; PREEMPT)
Locale: LANG=it_IT, LC_CTYPE=it_IT (charmap=ISO-8859-1) (ignored:
LC_ALL set to it_IT), LANGUAGE=it (charmap=ISO-8859-1) (ignored:
LC_ALL set to it_IT)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
Versions of packages cython3 depends on:
ii libc6 2.29-2
ii python3 3.7.3-1
Versions of packages cython3 recommends:
ii gcc 4:9.2.1-3.1
ii python3-dev 3.7.3-1
Versions of packages cython3 suggests:
pn cython-doc <none>
-- debconf-show failed
More information about the Python-apps-team
mailing list