Python Forum
Cython: How to compile to 32bit Windows with MinGW gcc?
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cython: How to compile to 32bit Windows with MinGW gcc?
#1
I converted my Python code with Cython to c code.
To convert the c code to an executable I use the gcc
of "MinGW-w64 - for 32 and 64 bit Windows".

The compilation to a working 64bit Windows exe works but
not to a working 32bit Windows exe. This is what I have
done so far:

I downloaded MinGW from https://sourceforge.net/projects/mingw-w...rce=navbar.

On their site they write: "MinGW-w64 - for 32 and 64 bit Windows"
Also I cannot find there a special MinGW32 version.
So I assume the MinGW64 gcc compiler can compile to 64 AND 32 bit Windows.

I used Cython to convert my py to a c file.

I installed Python 3.7 64 bit in C:\Python37 and Python 3.7 32 bit in C:\Python37-32bit

The following works and I get a 64bit exe that I can start without errors:

gcc -Wl,--subsystem,windows -municode -DMS_WIN64 -mthreads -Wall -O -IC:\Python37\include -LC:\Python37\libs example.c -lpython37 -o example.exe

(The -Wl,--subsystem,windows is to prevent a Dos windows.)

I read the parameter m32 in gcc is to get a 32 bit exe. So I tried this:

gcc -Wl,--subsystem,windows -m32 -municode -DMS_WIN64 -mthreads -Wall -O -IC:\Python37-32bit\include -LC:\Python37-32bit\libs example.c -lpython37 -o example.exe

I get no compile error. But if I start the example.exe I get a windows with this error message:

(Tried to translate my German message to English:)

example.exe - Application error
The application couldn't started correctly (0xc000007b).
Click on 'OK' to close the application. OK

Also I tested it with -m32 but without -Wl,--subsystem,windows if there are side effects
because both parameter have to do with Windows. But then I get the same error message
if I start example.exe.

I use tkinter in my program. Can that be a reason I get an error message if
I start the 32bit Windows example.exe?

This is my program example.py that I converted to a c file
with Cython an then to exe with the gcc of MinGW:

#Example (Hello, World):
import tkinter

tk = tkinter.Tk()
frame = tkinter.Frame(tk, relief="ridge", borderwidth=2)
frame.pack(fill="both",expand=1)
label = tkinter.Label(frame, text="Hallo Welt!")
label.pack(expand=1)
button = tkinter.Button(frame,text="OK",command=tk.destroy)
button.pack(side="bottom")

tk.mainloop()
So anybody knows why I can compile to a working 64 bit exe
with MinGW gcc but not to a working 32 bit exe?

What have I to do to get a working 32 bit exe with MinGW gcc?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I need to add data types to cython conversion python to c Good_AI_User 1 973 Aug-19-2022, 07:52 AM
Last Post: Gribouillis
  How to compile a Python script for a Windows / Linux executable? netanelst 2 1,279 May-24-2022, 07:02 AM
Last Post: netanelst
  unable to load an image with C (Cython) HLD202 0 1,280 Jan-13-2022, 09:16 PM
Last Post: HLD202
  Cython np.where slows down the code Johanoosterwaal 1 1,695 Sep-01-2021, 07:33 AM
Last Post: Johanoosterwaal
  How can I use Cython to protect my Python Code? TurboC 2 4,085 Dec-03-2020, 10:37 AM
Last Post: padma121
  Compile to Windows exe. SpongeB0B 6 3,708 Jul-06-2020, 08:44 AM
Last Post: snippsat
  Why does Cython generates bad code for Gentoo? AlekseyPython 1 1,819 Dec-26-2019, 01:57 PM
Last Post: AlekseyPython
  How I can speed up my Cython module? AlekseyPython 0 1,670 Oct-26-2019, 01:23 PM
Last Post: AlekseyPython
  Error in compiling cython extension on Python 3.6.4 on Windows 8 goldenmean 3 5,700 Jun-05-2019, 09:37 PM
Last Post: Larz60+
  cython does not work skorost5 5 4,184 Dec-19-2018, 09:23 AM
Last Post: skorost5

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020