Thread: File sizes

  1. #1
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114

    File sizes

    In DEV-C++, when I compile a simple hello world program, I've noticed, the size of the .exe compiled in DEV-C++ compared to the same code compiled in VC++ 9 Express is very different.

    Code:
    Code:
    #include <iostream>
    using namespace std;
    int main ()
    {
      cout << "Hello World!" << endl;
      cout << "Press ENTER to continue..." << endl; 
      cin.get();
      return 0;
    }
    EXE Compiled in DEV-C++ - 463 kb
    EXE Compiled in VC++ 9 XPress - 39 kb

    What?

    --------------------------------------------------------------------------------------------

    Also, can anyone tell me how to add an icon and file tags (Like description, copyright, ect.) in VC++ like you could in Dev-C++ through project options?

    Thanks everyone.
    OS: Windows XP Home Edition SP3, Windows 7 Ultimate Beta Build 7000
    LANGUAGES: C++, VB6
    SKILL: Novice/Intermediate

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Debug vs. Release will change the comparative sizes.
    Storing debug in the exe as opposed to storing debug in project files will change the comparative sizes.
    Static or dynamic linking with the run-time libraries will change the comparative sizes.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    Ok, thanks but that still doesn't make alot of sense to me.
    --------------------------------------------------------------------------------------
    Can anyone answer my second question?
    OS: Windows XP Home Edition SP3, Windows 7 Ultimate Beta Build 7000
    LANGUAGES: C++, VB6
    SKILL: Novice/Intermediate

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You may discover that VC++ exes may not start on other computers if they don't have the necessary support files that you get with VC++. You'd need to distribute those too (once the user has those, you probably won't need to redistribute them with the next program).

    MingW exe's don't rely on external files (unless your program does). You can just copy the exe to another machine and it would work there.

    For distributing I tend to compile with MingW (I don't really want to put other stuff into other people's computers).

    (To make MingW exes smaller, you can use the strip option and make sure that the exe doesn't contain debugging info.)
    Last edited by anon; 04-27-2008 at 03:33 AM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    So how would I make my exe a mingW exe in vc++?
    OS: Windows XP Home Edition SP3, Windows 7 Ultimate Beta Build 7000
    LANGUAGES: C++, VB6
    SKILL: Novice/Intermediate

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I really didn't have time to do that tutorial today guys... But I will put one up. This computer doesn't even have VC++ on it to give a quick idea. But you can manually configure your compiler commands. All you need to do is put the gcc commands. I am on the same boat as anon. All commercial PC software I've sold independent of some firm has had its final compile done with gcc since it doesn't require extras and its licensing is not dubious at all.

    Anyway, enough bs. Here is why I posted.

    http://upx.sourceforge.net/

    enjoy.

  7. #7
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    I don't really want to make it a whole bunch of files, I think i'll just look for another compiler with gcc/mingW.
    OS: Windows XP Home Edition SP3, Windows 7 Ultimate Beta Build 7000
    LANGUAGES: C++, VB6
    SKILL: Novice/Intermediate

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I don't really want to make it a whole bunch of files, I think i'll just look for another compiler with gcc/mingW.
    Eh, the MinGW port of g++ is a compiler. If you are looking for an IDE to use the MinGW port of g++ with, then I would suggest Code::Blocks.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    Using this code:
    Code:
    #define _WIN32_WINNT 0x0500
    #include <windows.h>
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <conio.h>
    #include <time.h>
    #include <cstdlib>
    #include <vector>
    
    struct CONSOLE_FONT
    {
    	DWORD index;
    	COORD dim;
    };//CONSOLE_FONT
    BOOL (WINAPI *SetConsoleFont)(HANDLE, DWORD);
    BOOL (WINAPI *GetConsoleFontInfo)(HANDLE, BOOL, DWORD, CONSOLE_FONT*);
    DWORD (WINAPI *GetNumberOfConsoleFonts)();
    
    //------------------------------------------------------------------------------
    
    
    //------------------------------------------------------------------------------
    
    template<typename pfn_t>
    inline bool LoadFunc(HMODULE hmod, const char *name, pfn_t &fn)
    {
    	fn = (pfn_t)GetProcAddress(hmod, name);
    	return fn != 0;
    }//LoadFunc
    
    //------------------------------------------------------------------------------
    
    
    
    
    
    
    
    
    using namespace std;
    int main()
    {
    
    
    
    
        char title[MAX_PATH];
        HWND hwnd;
    
        if (!::GetConsoleTitleA(title, sizeof(title)) ||
            !(hwnd = ::FindWindowA(0, title)))
        {
            cerr << "Failed to find console window" << endl;
            return 1;
        }//else
    
        // Undocumented API's
        HMODULE hmod = ::GetModuleHandleA("KERNEL32.DLL");
        if (!hmod ||
            !LoadFunc(hmod, "SetConsoleFont", SetConsoleFont) ||
            !LoadFunc(hmod, "GetConsoleFontInfo", GetConsoleFontInfo) ||
            !LoadFunc(hmod, "GetNumberOfConsoleFonts", GetNumberOfConsoleFonts))
        {
            cerr << "Failed to load API(s): " << ::GetLastError() << endl;
            return 1;
        }//if
    
        HANDLE hOut = ::GetStdHandle(STD_OUTPUT_HANDLE);
    
        // number of console fonts
        const DWORD MAX_FONTS = 40;
        DWORD num_fonts = GetNumberOfConsoleFonts();
        if (num_fonts > MAX_FONTS)
            num_fonts = MAX_FONTS;
    
        CONSOLE_FONT fonts[MAX_FONTS] = {0};
        GetConsoleFontInfo(hOut, 0, num_fonts, fonts);
    
        for (DWORD n = 0; n < num_fonts; ++n)
        {
            fonts[n].dim = GetConsoleFontSize(hOut, fonts[n].index);
    
            if (fonts[n].dim.X == 6 &&
                fonts[n].dim.Y == 8)
            {
                SetConsoleFont(hOut, fonts[n].index);
                ::InvalidateRect(hwnd, 0, FALSE);
                ::UpdateWindow(hwnd);
    
    
    
    system("cls");
    
        cout<<"___           ___       ___     _______      |        "<<endl;
    	Sleep(50);
        cout<<"\\           /          /  /    |  ____ \\     |        "<<endl;
    	Sleep(50);
        cout<<"  ___       ___       /  /     | |    \\ \\    |        "<<endl;
    	Sleep(50);
        cout<<"  \\       /          /  /      | |____/  |   |        "<<endl;
    	Sleep(50);
        cout<<"    ___   ___       |  |       |        /    |        "<<endl;
    	Sleep(50);
        cout<<"    \\   /           |  |       | ______/     |        "<<endl;
    	Sleep(50);
        cout<<"        ___         |  |       | |           |        "<<endl;
    	Sleep(50);
        cout<<"      /    \\        |  |       | |           |        "<<endl;
    	Sleep(50);
        cout<<"     ___  ___       |  |       | |           |        "<<endl;
    	Sleep(50);
        cout<<"    /        \\     \ \\  \\       | |           |        "<<endl;
    	Sleep(50);
        cout<<"   ___      ___      \\  \\      | |           |        "<<endl;
    	Sleep(50);
        cout<<"  /            \\      \\__\\     |_|           |        ";
    	Sleep(50);
        cout<<endl<<"_____________________________________________|       ";
    SetConsoleTitle("Xtended Command Prompt");
    
    
    system("color 0a");
    Sleep(1);
    system("color 0b");
    Sleep(1);
    system("color 0c");
    Sleep(1);
    system("color 0e");
    Sleep(1);
    system("color 0f");
    Sleep(1);
    system("color 0a");
    Sleep(1);
    system("color 0b");
    Sleep(1);
    system("color 0a");
    Sleep(1);
    system("color 0b");
    Sleep(1);
    
    
    
    
    cout<<endl<<      "                                             |";
    cout<<endl<<      "                                             |";
    cout<<endl<<      "Brad Szymanski XCP [Version 8.1.4000]        |"<<endl;
    cout<<            "Copyright (c) 2008 Brad Szymanski.           |"<<endl;
    cout<<            "All rights reserved.                         |"<<endl;
    cout<<            "                                             |"<<endl;
    char CM[9999];
    char PAATH[9999];
    ifstream inFile;
    system("color 0e");
    ::GetCurrentDirectoryA(9999,PAATH);
    while (1)
    {
          SetConsoleTitle("Xtended Command Prompt");
          cout<<"______________________________________________________________________________"<<endl;
          cout<<endl<<PAATH<<"> ";
          cin.getline(CM, 9999);
          cout<<endl;
          if (!stricmp(CM, "close"))
          {
                           return 0;
          }
    
          if (!stricmp(CM, "exit"))
          {
                           return 0;
          }
    
    
    	  if (!stricmp(CM, "checkcon"))
          {
    				cout<<"Checking connections..."<<endl<<endl;
    				system("netstat -n > CHECKCON1.txt");
    				Sleep(5000);
    				system("netstat -n > CHECKCON2.txt");
    				system("FC CHECKCON1.txt CHECKCON2.txt");
    				system("del CHECKCON1.txt /f /q");
    				system("del CHECKCON2.txt /f /q");
    				goto LULZ;
          }
    
    
    
    
         if ( !stricmp(CM, "thanks"))
        {
             cout<<endl<<"You're welcome"<<endl;
             goto LULZ;
        }
    
          if (!stricmp(CM, "cd"))
          {
                           cout<<endl<<"Path: ";
                           cin.getline(PAATH, 9999);
                           cout<<endl;
                           ::SetCurrentDirectory(PAATH);
                           cout<<"Path Changed to: "<<PAATH<<endl;
                           goto LULZ;
          }
    
    	   if ( !stricmp(CM, "checkcon /?"))
        {
            cout<<"Checks connection IPs, waits 5 seconds, checks again and"<<endl;
    		cout<<"displays the differences."<<endl;
            goto LULZ;
        }
    
    
    	   if ( !stricmp(CM, "flash"))
        {
    
    system("color 0a");
    Sleep(1);
    system("color 0b");
    Sleep(1);
    system("color 0c");
    Sleep(1);
    system("color 0e");
    Sleep(1);
    system("color 0f");
    Sleep(1);
    system("color 0a");
    Sleep(1);
    system("color 0b");
    Sleep(1);
    system("color 0a");
    Sleep(1);
    system("color 0b");
    Sleep(1);
    system("color 0a");
    Sleep(1);
    system("color 0b");
    Sleep(1);
    system("color 0c");
    Sleep(1);
    system("color 0e");
    Sleep(1);
    system("color 0f");
    Sleep(1);
    system("color 0a");
    Sleep(1);
    system("color 0b");
    Sleep(1);
    system("color 0a");
    Sleep(1);
    system("color 0b");
    Sleep(1);
    system("color 0e");
    
            goto LULZ;
        }
    
    
    
    
    
    
          if (!stricmp(CM, "cls"))
          {
                           system("cls");
    
        cout<<"___           ___       ___     _______      |        "<<endl;
    	Sleep(50);
        cout<<"\\           /          /  /    |  ____ \\     |        "<<endl;
    	Sleep(50);
        cout<<"  ___       ___       /  /     | |    \\ \\    |        "<<endl;
    	Sleep(50);
        cout<<"  \\       /          /  /      | |____/  |   |        "<<endl;
    	Sleep(50);
        cout<<"    ___   ___       |  |       |        /    |        "<<endl;
    	Sleep(50);
        cout<<"    \\   /           |  |       | ______/     |        "<<endl;
    	Sleep(50);
        cout<<"        ___         |  |       | |           |        "<<endl;
    	Sleep(50);
        cout<<"      /    \\        |  |       | |           |        "<<endl;
    	Sleep(50);
        cout<<"     ___  ___       |  |       | |           |        "<<endl;
    	Sleep(50);
        cout<<"    /        \\     \ \\  \\       | |           |        "<<endl;
    	Sleep(50);
        cout<<"   ___      ___      \\  \\      | |           |        "<<endl;
    	Sleep(50);
        cout<<"  /            \\      \\__\\     |_|           |        ";
    	Sleep(50);
        cout<<endl<<"_____________________________________________|       ";
    SetConsoleTitle("Xtended Command Prompt");
    cout<<endl<<      "                                             |";
    cout<<endl<<      "                                             |";
    cout<<endl<<      "Brad Szymanski XCP [Version 8.1.4000]        |"<<endl;
    cout<<            "Copyright (c) 2008 Brad Szymanski.           |"<<endl;
    cout<<            "All rights reserved.                         |"<<endl;
    cout<<            "                                             |"<<endl;
                           goto LULZ;
          }
    
    
    
    
    
          if (!stricmp(CM, "hide"))
          {
                              HWND stealth;
    						  AllocConsole();
    						  stealth=FindWindowA("ConsoleWindowClass",NULL);
    					      ShowWindow(stealth,0);
                              goto LULZ;
          }
    
    
    
    
    	  if (!stricmp(CM, "hide /?"))
          {
                           cout<<"Hides the console."<<endl;
                           goto LULZ;
          }
    
    
    
    
          else
          {
          system(CM);
          }
          LULZ:;
    
    }
          return 0;
    }
    }
    }
    I get this:
    C:\Users\bradszy\Documents\Projects\XCP Final\XCP FInal.cpp error: `GetConsoleFontSize' was not declared in this scope|
    In code::blocks.
    Makes Bradley sad.
    Compiles perfectly in VC++.
    OS: Windows XP Home Edition SP3, Windows 7 Ultimate Beta Build 7000
    LANGUAGES: C++, VB6
    SKILL: Novice/Intermediate

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    MingW exe's don't rely on external files (unless your program does). You can just copy the exe to another machine and it would work there.
    Note that while it doesn't require "extras," the file size increases. You could call it bloat if you want. All the data is stored inside the exe, so every exe will be big.
    On the other hand,

    Quote Originally Posted by anon View Post
    You may discover that VC++ exes may not start on other computers if they don't have the necessary support files that you get with VC++. You'd need to distribute those too (once the user has those, you probably won't need to redistribute them with the next program).
    Visual C++ doesn't put data into the exe, unless you use static linking. This has the advantage that the exes becomes smaller.
    But the target machine needs the runtime installed. But again, it only needs to be installed ONCE, and then it will always work, whatever program it is you install.

    Quote Originally Posted by master5001 View Post
    I am on the same boat as anon. All commercial PC software I've sold independent of some firm has had its final compile done with gcc since it doesn't require extras and its licensing is not dubious at all.
    Which makes this approach stupid IMHO.
    But that's just my take. Different people use different approaches and there's no right or wrong.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    Wait so If I use static linking, my application won't require installation?
    OS: Windows XP Home Edition SP3, Windows 7 Ultimate Beta Build 7000
    LANGUAGES: C++, VB6
    SKILL: Novice/Intermediate

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No runtime files will be needed (but any external component such as controls that your app relies on will still need to be on the target machine), but the filesize WILL go up. And it WILL increase for EVERY application/program you make.
    I find it better to redistribute runtime instead since you will gain a lot of size in the long run.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    EDIT:
    Never mind, but I still would rather compile a stand alone app, as it's only an emulation of CMD with added commands... I don't think it's going to be very big.
    SO can anyone educate me on my error?
    Last edited by bradszy; 04-28-2008 at 04:54 AM.
    OS: Windows XP Home Edition SP3, Windows 7 Ultimate Beta Build 7000
    LANGUAGES: C++, VB6
    SKILL: Novice/Intermediate

  14. #14
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by bradszy View Post
    Ok, thanks, but now i'm getting these:
    (Didn't change anything)
    You are probably not linking with your import library (xxx.lib, which corresponds to xxx.dll).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Btw, your indentation needs work.
    In Visual Studio, you can do... select all text, press Alt+F8. Boom! Indented!

    The functions are located in user32.dll, so you should link against user32.lib. In Visual Studio, though, this should be automatic. For other compilers/IDEs, I don't know.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  4. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM