Compiling Cython to EXE in Windows

1,670 views
Skip to first unread message

mdelaf...@uc.cl

unread,
Mar 26, 2017, 12:45:14 AM3/26/17
to cython-users
I have the file test.pyx:

print("Test")

I want to compile it to a standalone executable in my Windows machine (W10 - 64 bits). It seems there are two steps to do this:

First, we create the C file with the --embed option:
cython --embed -o test.c test.pyx

And then we compile it using GCC:
gcc test.c -IC:\Python34\include -LC:\Python34\libs -lpython34 -o test.exe

But I am getting the following error:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): In function `main':
C:/repo/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `
WinMain'
collect2.exe: error: ld returned 1 exit status

I have also looked up for this error and it seems to occur when the .c file doesn't have a main function. If you look at test.c, there's no main function, but I am not sure if this is actually the underlying problem.

I have wasted a few hours trying to solve this issue without success, please help. I am using MinGW (64 bits), Python 3.4 (64 bits) and Cython 0.25.2. 

Thanks.
Martín.

Jérôme Kieffer

unread,
Mar 26, 2017, 3:11:45 AM3/26/17
to cython...@googlegroups.com
On Sat, 25 Mar 2017 19:52:26 -0700 (PDT)
mdelaf...@uc.cl wrote:

> I have the file test.pyx:
>
> print("Test")
>
> I want to compile it to a standalone executable in my Windows machine (W10
> - 64 bits). It seems there are two steps to do this:
>
> First, we create the C file with the --embed option:
> cython --embed -o test.c test.pyx
>
> And then we compile it using GCC:
> gcc test.c -IC:\Python34\include -LC:\Python34\libs -lpython34 -o test.exe
>
> But I am getting the following error:
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64
> -w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): In
> function `main':
> C:/repo/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18:
> undefined reference to `WinMain'
> collect2.exe: error: ld returned 1 exit status
>
> I have also looked up for this error and it seems to occur when the .c file
> doesn't have a *main *function. If you look at test.c, there's no *main *function,
> but I am not sure if this is actually the underlying problem.
>
> I have wasted a few hours trying to solve this issue without success,
> please help. I am using MinGW (64 bits), Python 3.4 (64 bits) and Cython
> 0.25.2.

Could you give a try with the official windows compiler ?

It may greatly help, as linking on windows64 is tricky.


金逸飞

unread,
Feb 26, 2018, 12:54:38 AM2/26/18
to cython-users
Did you solve the issue finally? I meet the same issue and cannot find a feasible method.
I use MinGW+Anaconda3+Cython.

Best,
Yifei
Reply all
Reply to author
Forward
0 new messages