(Linked to Cython without Console on Windows but this one is for Python 2.7 and mingw, the solutions don't work directly here)
This allows to create a .exe with Cython:
cython test.py --embed
call vcvarsall.bat x64
cl test.c /I C:\Python38\include /link C:\Python38\libs\python38.lib
It works, and then test.exe starts the program in a terminal console window.
How to compile with cython --embed it without a console window?
I tried
cl test.c /I C:\Python38\include /link C:\Python38\libs\python38.lib /subsystem:window
but it fails with:
LIBCMT.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol WinMain referenced in function "int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ)
Cython produces usually
wmaininstead ofmainso you could use widechar as command line argument when calling the resulting executable.Thus you need to tell the linker to look for
wmainthis is done via option:which differently as
mainCRTStartupwill look forwmain.It is important to use
/ENTRY:wmainCRTStartupand not just/ENTRY:wmainbecause otherwise the code, which should run beforewmainis called (e.g. initialization of static variables) won't run.The full solution is then: