Ошибка связывания при компиляции Cython на aarch64

#c #cython #arm64 #cythonize

Вопрос:

Я пытаюсь создать исполняемый файл на aarch64 с помощью cython.

Я знаю, что эти флаги чрезмерны, я попытался скомпилировать их в своей системе x86_64, и это сработало только с gcc -I/usr/include/python3.9 -lpython3.9 sample.c aarch64, но в aarch64 это приводит к таким длинным ошибкам связывания.

Если кому-то удалось создать исполняемый файл на arm64 с помощью cython, это также помогло бы.

 root@f6753f1e6043:~# cython sample.pyx --embed -X language_level=3
 
 root@f6753f1e6043:~# python3-config --ldflags --libs --cflags --embed
-L/usr/lib/python3.8/config-3.8-aarch64-linux-gnu -L/usr/lib -lpython3.8 -lcrypt -lpthread -ldl  -lutil -lm -lm 
-lpython3.8 -lcrypt -lpthread -ldl  -lutil -lm -lm 
-I/usr/include/python3.8 -I/usr/include/python3.8  -Wno-unused-result -Wsign-compare -g -fdebug-prefix-map=/build/python3.8-pqDzXG/python3.8-3.8.10=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector -Wformat -Werror=format-security  -DNDEBUG -g -fwrapv -O3 -Wall

 
 root@f6753f1e6043:~# gcc $(python3-config --ldflags --libs --cflags --embed) sample.c
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `__Pyx_PyObject_GetAttrStr':
/root/sample.c:1489: undefined reference to `PyObject_GetAttr'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `__Pyx_copy_spec_to_module':
/root/sample.c:1258: undefined reference to `PyObject_GetAttrString'
/usr/bin/ld: /root/sample.c:1261: undefined reference to `_Py_NoneStruct'
/usr/bin/ld: /tmp/ccBjCsrj.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_Py_NoneStruct' which may bind externally can not be used when making a shared object; recompile with -fPIC
/root/sample.c:1261:(.text.unlikely 0xbc): dangerous relocation: unsupported relocation
/usr/bin/ld: /root/sample.c:1261: undefined reference to `_Py_NoneStruct'
/usr/bin/ld: /root/sample.c:1262: undefined reference to `PyDict_SetItemString'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `_Py_DECREF':
/usr/include/python3.8/object.h:478: undefined reference to `_Py_Dealloc'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `__Pyx_copy_spec_to_module':
/root/sample.c:1265: undefined reference to `PyExc_AttributeError'
/usr/bin/ld: /tmp/ccBjCsrj.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `PyExc_AttributeError' which may bind externally can not be used when making a shared object; recompile with -fPIC
/root/sample.c:1265:(.text.unlikely 0xfc): dangerous relocation: unsupported relocation
/usr/bin/ld: /root/sample.c:1265: undefined reference to `PyExc_AttributeError'
/usr/bin/ld: /root/sample.c:1265: undefined reference to `PyErr_ExceptionMatches'
/usr/bin/ld: /root/sample.c:1266: undefined reference to `PyErr_Clear'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `__Pyx_check_single_interpreter':
/root/sample.c:1237: undefined reference to `PyThreadState_Get'
/usr/bin/ld: /root/sample.c:1237: undefined reference to `PyInterpreterState_GetID'
/usr/bin/ld: /root/sample.c:1250: undefined reference to `PyExc_ImportError'
/usr/bin/ld: /tmp/ccBjCsrj.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `PyExc_ImportError' which may bind externally can not be used when making a shared object; recompile with -fPIC
/root/sample.c:1250:(.text.unlikely 0x17c): dangerous relocation: unsupported relocation
/usr/bin/ld: /root/sample.c:1250: undefined reference to `PyExc_ImportError'
/usr/bin/ld: /root/sample.c:1250: undefined reference to `PyErr_SetString'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `__pyx_pymod_create':
/root/sample.c:1278: undefined reference to `PyObject_GetAttrString'
/usr/bin/ld: /root/sample.c:1280: undefined reference to `PyModule_NewObject'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `_Py_DECREF':
/usr/include/python3.8/object.h:478: undefined reference to `_Py_Dealloc'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `__pyx_pymod_create':
/root/sample.c:1283: undefined reference to `PyModule_GetDict'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `_Py_DECREF':
/usr/include/python3.8/object.h:478: undefined reference to `_Py_Dealloc'
/usr/bin/ld: /tmp/ccBjCsrj.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `__stack_chk_guard@@GLIBC_2.17' which may bind externally can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /tmp/ccBjCsrj.o(.text.unlikely 0x2e0): unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol `__stack_chk_guard@@GLIBC_2.17'
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
 

Комментарии:

1. relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `PyExc_AttributeError' which may bind externally can not be used when making a shared object; recompile with -fPIC Возможно, эта ошибка и является основной причиной.

2. @kiner_shah попробовал, но ничего не вышло

3. Что не сработало? Что ты пробовал? Какие-нибудь сообщения об ошибках?