Menu

Why is console executable bigger than Win?

2008-05-16
2012-09-26
  • Bryan Miller

    Bryan Miller - 2008-05-16

    I am curious why a compiled console version of "hello world" is 72 kb while the Windows GUI equivalent is only 4 kb. Does it have to do with my include statements? Here is my code for each program, first the console and then the Windows version:

    include <iostream.h>

    include <stdio.h>

    include <stdlib.h>

    int main()
    {
    cout << "Hello World!" << endl;

    cout << "Press ENTER to continue..." << endl;
    getchar ();
    return 0;
    }


    include <windows.h>

    int WINAPI WinMain (HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    PSTR szCmdLine,
    int iCmdShow)
    {
    MessageBox (NULL, "Hello", "Hello Demo", MB_OK);
    return (0);
    }

     
    • cpns

      cpns - 2008-05-16

      <iostream> is a large statically linked library. The Windows API on the other hand is provided to your app as a DLL so does not form part of the executable.

      Since in MinGW the C library is also a DLL, if you want small executables, use the C library only.

      It is largely a fixed overhead, so for any significantly sized application it will make not be significant. Don't sweat the small stuff.

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.