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!

6
  • See if this applies, stackoverflow.com/questions/5259714/… and/or try adding for example -mconsole compile flag. Commented Jan 22, 2016 at 2:42
  • I tried that, but it did not work either :( Commented Jan 23, 2016 at 0:31
  • I think you should edit your question, and put in more detail what you are trying to do, like the commands used to compile and link. Also the cython command used. Commented Jan 23, 2016 at 0:33
  • @J.J.Hakala. Thank you. I just edited it. Commented Jan 23, 2016 at 0:41
  • Do you have a method named main() in your .pyx file? Commented Jan 23, 2016 at 0:44

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for that advice. What operating system are you using, perchance? Because it tells me that the line option "-municode" does not exist
@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.
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
I get undefined reference to `wWinMain'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.