Archived

This topic is now archived and is closed to further replies.

Webbster

4mb Just for cout?

Recommended Posts

Okay so, just recently I've been noticing a huge drop in Hard-Drive space, and all this fits in with my programming, so i open my main programming folder (where i keep all my VC++ projects) to find that it totals to around 20mb!! Just for a few (4) console based programs. To test just how weird this is, i created a very very basic program for the console:
 

#include <iostream>

using namespace std;

int main()
{
     cout << "Hello World!";
     return 0;
}

Okay very simple! Then i compile it only to find that the project is 4MB! im using VC++ 6.0, have i not configured something correctly, whats going on? Thanks Ad PS Anyone providing help please keep it simple for me (i am not very familiar with the VC++ 6 program, just C++, maybe i should get a book lol) [edited by - Webbster on September 3, 2003 12:38:11 PM]

Share this post


Link to post
Share on other sites
1: Compile with ''Release'' settings.
2: Discard unused libs with linker options (''Release'' already handles this, if you''ve not changed the settings).
3: Turn on optimization for small code (in compiler options).
4: Make sure you don''t compile debug info into the exe.
5: Make sure the align size is sane.

And such...

rgds Nik

Share this post


Link to post
Share on other sites
There can also be a lot of intermediate files created by VC in the Debug or Release folder within your project directory. In most cases it is harmless to delete most of those, at the expense of a total recompile the next time you''d need to compile.

Share this post


Link to post
Share on other sites
The same code, using mingw32-g++, totals 220kB once stripped.

Unlike the C library, a lot of the C++ library always gets compiled in with your code. The first use of a given library function may therefore be costly, but further use isn''t - your example is an extreme case of that. Decent platforms however, do keep iostreams in a library you can dynamically link against - try linking against the "Multithreaded DLL" runtime (/MD or /MDd for debug)

There are techniques to reduce executable size.

Share this post


Link to post
Share on other sites
Okay thats got it down to 2mb.

Could these files have anything to do with it:

\debug\test.pch
\debug\main.obj
\debug\vc60.idb
\debug\vc60.pdb

The compiler keeps creating them and the test.pch file is the largest at around a megabyte, anyway of turning these off or is this the smallest file size I can get the entire project?

Share this post


Link to post
Share on other sites
VC creates them for various reasons. You can delete them whenever you want, but they''ll be recreated, and deleting them every time will slow down builds. But why would you care about this? these files aren''t required to be released with your program.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
If you are programming on a large project, these files can easily total 20 mb(My current project). No big deal, imho. When I think a project is completed(Everything works as it should to my idea) I release the application/game/etc. and delete all the intermediate files in the Debug and Release folders. I just leave the exes in the directories(Well, only release mode exe).

Toolmaker



-Earth is 98% full. Please delete anybody you can.

Share this post


Link to post
Share on other sites
A hello world app using stdio.h is only 22kb on dev-c++

Stripping it reduces its size to about 10kB.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
quote:
Original post by Fruny
A hello world app using stdio.h is only 22kb on dev-c++

Stripping it reduces its size to about 10kB.


I just compiled this program with GCC 3.2.3, using this command line:
gcc -O3 -fomit-frame-pointer helloworld.c -o helloworld.exe -s 


#include <stdio.h>

int main(int agrc,char* argv[])
{
printf("Hello world\n");
return 0;
}


It gave me an executable with a size of 5120 bytes.

Then, I compressed it using UPX 1.24, with highest compression. I then had an executable with a size of 3072 bytes.

It is obviously possible to get small executables. However, and slightly more on topic, if you do the same program, but use std::cout instead of printf, and compile using g++ instead of gcc, the executable is ~208kb. When UPXed, about 50kb. So obviously the standard C++ library is quite large.

[edited by - AikonIV on September 3, 2003 2:16:45 PM]

Share this post


Link to post
Share on other sites
the pch (if i remember it stands for pre-compiled header) files and the obj (object, again if i remember correctly) are gonna be big, its nothing to worry about. the executable file shouldnt be too big, and as other people have mentioned it can be easily stripped down to a much smaller size.

Share this post


Link to post
Share on other sites
It''s even possible to make a midi player with 3 minutes of music and make the player with the sound included in the executable file (eg. resource file) smaller then the original resource file only. (if you use UPX).

Share this post


Link to post
Share on other sites
You can disable the .pch file (in VC6) by going into the project settings and under "C/C++" and "Precompiled Headers", set it to "Not using precompiled headers"... that should prevent it from being re-generated. There is something similar for VC7, but I''m not sure where exactly it lives.

.obj files must be generated for the linker. If you really want to you can delete them after the build is completed.

The .idb and .pdb are debug symbols. You can disable them by going to project settings, "Link", and "General", and make sure "Generate debug info" is deselected. Then, of course, you will be stuck debugging raw assembly :/

Also, while you''re in that Link/General section, cut every library listed in the "Object/library modules" out into notepad and add them in one by one as necessary. This might help, but probably won''t make any difference for a release build.

Share this post


Link to post
Share on other sites
i got 40 kb compiling in vis c++6 the same program, if you want to keep your simple console apps really small, go to project settings, then in your linker settings for all configurations, delete all libs but kernel32.lib, then, in the c/c++ tab, select for the optimization minimal size instead of maximum speed. make sure to choose win32 release before building.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
that simple code should build to a 4kb release exe. i just tested it out with vc++ 6 and the total project files add up to 148kb, with 103kb of that taken up by the ncb and opt files. the exe is 4kb, the obj is 4kb, and the idb is 33kb.

btw, the lib list for the linker has absolutely nothing to do with the size of your project, let alone your exe. it is simply a list of libs that the linker may potentially search through when attempting to resolve external references within the object files that make up the project. the linker will not pull in unncessary libs and/or library entries and make them part of the exe. it is possible to have unused functions from a library pulled in, depending upon how the lib was built, but there is a linker option to even strip these out of the final build.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by NafdahliX
quote:
I''ve been noticing a HUGE drop in Hard-Drive space ...


haha, lol, you must have the smallest harddrive ever



Well, it''d make a difference on my 80486 laptop, since with debian & the necessary stuff installed it only has like 35 of the HDD''s 320 MB free for other stuff.
yet i reckon the OP uses a more capable machine.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
if you dont know how to set it into release mode just delete the debug folder

I had this problem in my c++ class at school..

i resolved the problem by not keeping any of the projects
after i would complete/pass in an assignment i would just keep the source code and delete the rest of the junk

Share this post


Link to post
Share on other sites