(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)
CodePudding user response:
Cython produces usually wmain
instead of main
so you could use widechar as command line argument when calling the resulting executable.
Thus you need to tell the linker to look for wmain
this is done via option:
/ENTRY:wmainCRTStartup
which differently as mainCRTStartup
will look for wmain
.
It is important to use /ENTRY:wmainCRTStartup
and not just /ENTRY:wmain
because otherwise the code, which should run before wmain
is called (e.g. initialization of static variables) won't run.
The full solution is then:
cl test.c /I C:\Python38\include /link C:\Python38\libs\python38.lib /subsystem:windows /ENTRY:wmainCRTStartup