using functions from complex.h on Windows (MSVC)

822 views
Skip to first unread message

Alex Pitchford

unread,
Feb 4, 2017, 1:46:24 PM2/4/17
to cython-users
Does anyone have any advice on how to use functions declared in complex.h on Windows?

I am trying to cythonize pyx files that are written assuming C99 compiler. We would like to compile using the MSVC compiler for py>=3.5. I have installed VisualStudio 14

If I simply include:
cdef extern from "complex.h":
    double complex conj(double complex x)

I get these compilation errors:
conj.c
conj.c(666): error C2061: syntax error: identifier '__pyx_t_double_complex'
conj.c(666): error C2059: syntax error: ';'
conj.c(671): error C2061: syntax error: identifier '__pyx_t_double_complex_from_parts'
conj.c(671): error C2059: syntax error: ';'
conj.c(671): error C2059: syntax error: '<parameter-list>'
conj.c(1203): error C2061: syntax error: identifier '__pyx_t_double_complex_from_parts'
conj.c(1203): error C2059: syntax error: ';'
conj.c(1203): error C2059: syntax error: '<parameter-list>'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

Robert Bradshaw

unread,
Feb 4, 2017, 5:11:54 PM2/4/17
to cython...@googlegroups.com
On Fri, Feb 3, 2017 at 4:49 AM, Alex Pitchford <alex.pi...@gmail.com> wrote:
Does anyone have any advice on how to use functions declared in complex.h on Windows?

I am trying to cythonize pyx files that are written assuming C99 compiler. We would like to compile using the MSVC compiler for py>=3.5. I have installed VisualStudio 14

MSVC simply doesn't properly support complex numbers as defined by C99. If you can't avoid MSVC, your best bet is probably to compile with C++ which will cause Cython to use the class definitions from <complex> instead. 

If I simply include:
cdef extern from "complex.h":
    double complex conj(double complex x)

I get these compilation errors:
conj.c
conj.c(666): error C2061: syntax error: identifier '__pyx_t_double_complex'
conj.c(666): error C2059: syntax error: ';'
conj.c(671): error C2061: syntax error: identifier '__pyx_t_double_complex_from_parts'
conj.c(671): error C2059: syntax error: ';'
conj.c(671): error C2059: syntax error: '<parameter-list>'
conj.c(1203): error C2061: syntax error: identifier '__pyx_t_double_complex_from_parts'
conj.c(1203): error C2059: syntax error: ';'
conj.c(1203): error C2059: syntax error: '<parameter-list>'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Cournapeau

unread,
Feb 6, 2017, 8:27:10 AM2/6/17
to cython...@googlegroups.com
On Fri, Feb 3, 2017 at 12:49 PM, Alex Pitchford <alex.pi...@gmail.com> wrote:
Does anyone have any advice on how to use functions declared in complex.h on Windows?

I am trying to cythonize pyx files that are written assuming C99 compiler. We would like to compile using the MSVC compiler for py>=3.5. I have installed VisualStudio 14

If you want any kind of decent C99 support with ABI compatibility on windows, your best bet are the Intel Compilers. Using C99 complex with MSVC in C mode (not C++) is just going to bring a lot of pain.

David
 

If I simply include:
cdef extern from "complex.h":
    double complex conj(double complex x)

I get these compilation errors:
conj.c
conj.c(666): error C2061: syntax error: identifier '__pyx_t_double_complex'
conj.c(666): error C2059: syntax error: ';'
conj.c(671): error C2061: syntax error: identifier '__pyx_t_double_complex_from_parts'
conj.c(671): error C2059: syntax error: ';'
conj.c(671): error C2059: syntax error: '<parameter-list>'
conj.c(1203): error C2061: syntax error: identifier '__pyx_t_double_complex_from_parts'
conj.c(1203): error C2059: syntax error: ';'
conj.c(1203): error C2059: syntax error: '<parameter-list>'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

--

Denis Akhiyarov

unread,
Feb 8, 2017, 1:27:35 AM2/8/17
to cython-users
conda provides m2w64-gcc for python 3.5, it may still be funky with ucrt.

Alex Pitchford

unread,
Feb 8, 2017, 7:37:46 AM2/8/17
to cython-users
Thanks, this would be quite quick for me to test, so I will give it a try.
conda is our support env, so would be good solution.

Alex Pitchford

unread,
Feb 8, 2017, 7:37:52 AM2/8/17
to cython-users
I think Intel compilers are not free to use. Our library does some dynamic compilation and hence I need a solution that is free for end users.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.

Alex Pitchford

unread,
Feb 8, 2017, 7:37:56 AM2/8/17
to cython-users
Thanks, I was trying the MSVC compiler as almost all of what I read tells me that extensions should be compiled using the same compiler that is used for Python, which I am is apparently MSVC v14 for Python 3.5 on Windows.
C++ could be an option. Might take a bit of work though. I will try it.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages