Я собираю библиотеку C для python, используя "python.h", я успешно создал одну для добавления двух чисел: build-it и install-it. Но теперь я хочу добавить эти числа с помощью встроенного ассемблерного кода на языке C. Но когда я собираю файл C с помощью файла setup.py, он выдает ошибку. Кто-нибудь сделал что-то подобное и, вероятно, есть решения? Или у вас есть другие идеи сделать это.
Вот мой hectorASMmodule.c
#include <Python.h>
#include <stdio.h>
static PyObject *hectorASM_ADD(PyObject *self, PyObject *args) {
int num1, num2;
if (!PyArg_ParseTuple(args, "ii", &num1, &num2)) {
return NULL;
}
// int res = num1 + num2;
int res = 0;
__asm__("add %%ebx, %%eax;" : "=a"(res) : "a"(num1), "b"(num2));
return Py_BuildValue("i", res);
}
static PyMethodDef hectorASM_methods[] = {
// "PythonName" C-function Name argument presentation description
{"ADD", hectorASM_ADD, METH_VARARGS, "Add two integers"},
{NULL, NULL, 0, NULL} /* Sentinel */
};
static PyModuleDef hectorASM_module = {
PyModuleDef_HEAD_INIT,
"hectorASM",
"My own ASM functions for python",
0,
hectorASM_methods
};
PyMODINIT_FUNC PyInit_hectorASM() {
return PyModule_Create(&hectorASM_module);
}
А вот и мой setup.py
from distutils.core import setup, Extension, DEBUG
module1 = Extension(
'hectorASM',
sources = ['hectorASMmodule.c']
)
setup (
name = 'hectorASM',
version = '1.0',
description = 'My own ASM functions for python',
author = 'hectorrdz98',
url = 'http://sasukector.com',
ext_modules = [module1]
)
Вот ошибка, которую я получил при запуске python setup.py build
, он говорит, что ' asm ' не определен.
hectorASMmodule.c
hectorASMmodule.c(11): warning C4013: '__asm__' sin definir; se supone que extern devuelve como resultado int
hectorASMmodule.c(11): error C2143: error de sintaxis: falta ')' delante de ':'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2