Pergunta

I'm creating this dll (pyd) in Cython:

from libcpp.string cimport string

cpdef public char* say_hello():
    py_byte_string = 'hello'.encode('UTF-8')
    cdef char* c_string = py_byte_string
    return c_string

Then, I run this command line:

python setup.py build_ext --inplace

So, I get this follow error:

running build_ext cythoning helloworld.pyx to helloworld.c building 'helloworld' extension c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python26\include -IC:\Python26\ obuild\temp.win32-2.6\Release\helloworld.obj helloworld.c c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(19) : error C2061: syntax error : identifier 'acosf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(19) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(19) : error C2061: syntax error : identifier 'asinf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(19) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(20) : error C2061: syntax error : identifier 'atanf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(20) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(20) : error C2061: syntax error : identifier 'atan2f' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(20) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(20) : error C2061: syntax error : identifier 'ceilf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(20) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(21) : error C2061: syntax error : identifier 'cosf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(21) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(21) : error C2061: syntax error : identifier 'coshf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(21) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(21) : error C2061: syntax error : identifier 'expf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(21) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(22) : error C2061: syntax error : identifier 'fabsf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(22) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(22) : error C2061: syntax error : identifier 'floorf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(22) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(22) : error C2061: syntax error : identifier 'fmodf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(22) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(23) : error C2061: syntax error : identifier 'frexpf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(23) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(23) : error C2061: syntax error : identifier 'ldexpf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(23) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(23) : error C2061: syntax error : identifier 'logf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(23) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(24) : error C2061: syntax error : identifier 'log10f' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(24) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(24) : error C2061: syntax error : identifier 'modff' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(24) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(24) : error C2061: syntax error : identifier 'powf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(24) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(25) : error C2061: syntax error : identifier 'sinf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(25) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(25) : error C2061: syntax error : identifier 'sinhf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(25) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(25) : error C2061: syntax error : identifier 'sqrtf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(25) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(26) : error C2061: syntax error : identifier 'tanf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(26) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(26) : error C2061: syntax error : identifier 'tanhf' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(26) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(28) : error C2061: syntax error : identifier 'acosl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(28) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(28) : error C2061: syntax error : identifier 'asinl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(28) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(29) : error C2061: syntax error : identifier 'atanl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(29) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(29) : error C2061: syntax error : identifier 'atan2l' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(29) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(29) : error C2061: syntax error : identifier 'ceill' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(29) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(30) : error C2061: syntax error : identifier 'cosl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(30) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(30) : error C2061: syntax error : identifier 'coshl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(30) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(30) : error C2061: syntax error : identifier 'expl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(30) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(31) : error C2061: syntax error : identifier 'fabsl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(31) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(31) : error C2061: syntax error : identifier 'floorl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(31) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(31) : error C2061: syntax error : identifier 'fmodl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(31) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(32) : error C2061: syntax error : identifier 'frexpl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(32) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(32) : error C2061: syntax error : identifier 'ldexpl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(32) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(32) : error C2061: syntax error : identifier 'logl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(32) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(33) : error C2061: syntax error : identifier 'log10l' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(33) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(33) : error C2061: syntax error : identifier 'modfl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(33) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(33) : error C2061: syntax error : identifier 'powl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(33) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(34) : error C2061: syntax error : identifier 'sinl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(34) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(34) : error C2061: syntax error : identifier 'sinhl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(34) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(34) : error C2061: syntax error : identifier 'sqrtl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(34) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(35) : error C2061: syntax error : identifier 'tanl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(35) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(35) : error C2061: syntax error : identifier 'tanhl' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(35) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(37) : error C2061: syntax error : identifier 'abs' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(37) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(39) : error C2061: syntax error : identifier 'acos' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(39) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(39) : error C2061: syntax error : identifier 'asin' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(39) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(40) : error C2061: syntax error : identifier 'atan' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(40) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(40) : error C2061: syntax error : identifier 'atan2' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(40) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(40) : error C2061: syntax error : identifier 'ceil' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(40) : error C2059: syntax error : ';' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(41) : error C2061: syntax error : identifier 'cos' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\cmath(41) : fatal error C1003: error count exceeds 100; stopping compilation error: command '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\cl.exe"' failed with exit status 2

This error occurrs because of this import:

from libcpp.string cimport string

I am using this import because I want to use my method with parameter "string" instead of "char *" like this:

cpdef public string say_hello():

And this is my setup.py:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
    cmdclass = {'build_ext': build_ext},
    ext_modules = [Extension("helloworld",
["helloworld.pyx"])], requires=['Cython'] )

Any Idea to solve this?

Foi útil?

Solução

# distutils: language = c++

Add this to the first line in your .pyx script.

Outras dicas

You need the language="c++":

setup(
    cmdclass = {'build_ext': build_ext},
    ext_modules = [Extension("helloworld",
       ["helloworld.pyx"])], 
    requires=['Cython'],
    language='c++'
)

The cython docs give other info related to binding to C++.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top