当我尝试用Cython包装C ++函数时,我遇到编译器错误。我有一个超级简单的C ++程序打印“Hello World”,我无法弄清楚如何解决这个错误。我认为它与分配给主函数的数据类型有关,但我不确定从哪里开始......
的hello.c
#include<stdio.h>
#include <Python.h>
int main()
{
printf("Hello World");
}
helloworld.pyx
cdef extern from "hello.c":
cpdef main()
最后,setup.py
try:
from setuptools import setup
from setuptools import Extension
from Cython.Distutils import build_ext
except ImportError:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
ext_modules = [Extension(
"hello_world",
sources=["helloworld.pyx"],
language="c++", # this causes Cython to create C++ source
)]
setup(
name='Hello World',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)
当我运行python setup.py build_ext --inplace
时,我收到以下错误:helloworld.cpp(1253): error C2664: __Pyx_CFunc_object____to_py : cannot convert parameter 1 from int (__cdecl *)(void) to PyObject *(cdecl *)(void) None of the functions with this name in scope match the target type