Форум сайта python.su
В Qt Creator я создал маленьку библиотеку возведения в квадрат:
squaring.h:
int squaring(int a);
#include "squaring.h"
int squaring(int a){
return a * a;
}
cdef extern from "/home/denis/Squaring/squaring.h": int squaring(int a)
cimport cSquaring cpdef int count(int value): return cSquaring.squaring(value)
from distutils.core import setup from distutils.extension import Extension from Cython.Build import cythonize setup(ext_modules=cythonize([Extension("Functions", ["Functions.pyx"])]))
from Functions import count if __name__ == '__main__': data = 1 returned = count(data) print(returned)
python3 setup.py build_ext -i
File “/home/denis/.p2/pool/plugins/org.python.pydev.core_7.3.0.201908161924/pysrc/pydevd.py”, line 2643, in <module>
main()
File “/home/denis/.p2/pool/plugins/org.python.pydev.core_7.3.0.201908161924/pysrc/pydevd.py”, line 2636, in main
globals = debugger.run(setup, None, None, is_module)
File “/home/denis/.p2/pool/plugins/org.python.pydev.core_7.3.0.201908161924/pysrc/pydevd.py”, line 1920, in run
return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
File “/home/denis/.p2/pool/plugins/org.python.pydev.core_7.3.0.201908161924/pysrc/pydevd.py”, line 1927, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File “/home/denis/.p2/pool/plugins/org.python.pydev.core_7.3.0.201908161924/pysrc/_pydev_imps/_pydev_execfile.py”, line 25, in execfile
exec(compile(contents+“\n”, file, ‘exec’), glob, loc)
File “/home/denis/eclipse-workspace/ConnectionWithCPlusPlus/main.py”, line 1, in <module>
from Functions import count
ImportError: /home/denis/eclipse-workspace/ConnectionWithCPlusPlus/Functions.cpython-37m-x86_64-linux-gnu.so: undefined symbol: squaring
Отредактировано Sanya28 (Ноя. 13, 2019 14:03:00)
Офлайн
Для будущих поколений напишу, что в pyx- файле не хватало заголовка:
# distutils: sources = Squaring/squaring.c
Отредактировано Sanya28 (Ноя. 13, 2019 15:50:52)
Офлайн