How to hide windows console in c++ tcc

668 views Asked by At

How to hide console window, Compiler is tiny C

//Tiny C -> http://download.savannah.gnu.org/releases/tinycc/
#include <stdlib.h>
int main()
{
    system("Taskkill /IM test.exe /F");
    return 0;
}
1

There are 1 answers

0
vitalyster On BEST ANSWER

When operating system starts application, it lookups special description table in EXE file called IMAGE_OPTIONAL_HEADER. This structure contains so called Subsystem field. When Subsystem is IMAGE_SUBSYSTEM_WINDOWS_CUI - OS attaches console window to this process. Otherwise, console window will not be added.

Compilers/linkers usually have parameters to set output application subsystem type, e.g. when you link your code using Microsoft Linker you can add /SUBSYSTEM:WINDOWS parameter and you will not see console window when starting your application.

The other way: compiler may automatically decide to set EXE subsystem to Console when seeing main function in your code, or set GUI subsystem when you have WinMain as entry point.

About TCC: I see -Wl,-subsystem=gui option in TCC documentation, but seems it is not worked. So try to send a bugreport or use more mature compiler/linker.