2

I am trying to create an executable in cython, following the directions here: Making an executable in Cython. However, I keep getting the error "undefined reference to 'WinMain@16' collect2.exe and I am curious to know what the cause of this is.

Edited:

I am currently doing the following things with the following Cython file:

cpdef primes(int kmax):
cdef int n, k, i
cdef int p[1000]
result = []
if kmax > 1000:
    kmax = 1000
k = 0
n = 2
while k < kmax:
    i = 0
    while i < k and n % p[i] != 0:
        i = i + 1
    if i == k:
        p[k] = n
        k = k + 1
        result.append(n)
    n = n + 1
return result
  1. Running through the command line the commands:

cython primes.pyx --embed

gcc -DMS_WIN64 -mthreads -mconsole -Wall -O -IC:\Python34\include -LC:\Python34\libs setup.c -lpython34 -o example.exe

And the error that I get is:

"c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libmingw32.a(main.o):(.text.startup+0xa7): undefined reference to `WinMain@16'"

Thank you kindly!

Community
  • 1
  • 1
littlebluedeer
  • 103
  • 1
  • 9

1 Answers1

1

The following command compiled your cython program

gcc -municode -DMS_WIN64 -O -Wall -I /c/devel/Python34/include -L /c/devel/Python34/libs/ primes.c -lpython34 -o example.exe

This was done in a windows 7 64bit msys2 environment using gcc 4.9.1 and 5.3.0 64bit versions (win32 threads, SEH exception handling) and 64bit python 3.4.

My original thought was that there would be a problem because of missing main() but cython silently adds one.

J.J. Hakala
  • 6,136
  • 6
  • 27
  • 61
  • Thank you for that advice. What operating system are you using, perchance? Because it tells me that the line option "-municode" does not exist – littlebluedeer Jan 23 '16 at 01:16
  • @smallfacebigmouth I did not notice that you had rather old compiler i.e. 4.8.1. I think it is a poor match when working with Python 3.4 since it does not have `-municode` like newer version. *python --embed* produces code that needs unicode support from compiler. – J.J. Hakala Jan 23 '16 at 08:50
  • Yes, I noticed that as well. I worked around that by ignoring the -municode and when the .c file is generated from Cython, to replace the "wmain" with "main". That did the trick – littlebluedeer Jan 23 '16 at 19:37
  • I get undefined reference to `wWinMain' – Zibri Jul 22 '23 at 18:57