Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Huge C++ Programs For Hellowprld!! (http://www.programmingforums.org/showthread.php?t=1117)

Dia_Byte Nov 12th, 2004 6:09 AM

HELP!!!!!!!!

i'm using DEV_CPP and i am getting 100KB+ programs for a simple code that prints "hello world" to the screen !!!!

how can i reduce the size of my programs ??

Benoit Nov 12th, 2004 8:52 AM

Thats crazy.....Because I made a simple text file encryption program and it was only 5KB

Pizentios Nov 12th, 2004 9:40 AM

You must be doing somthing wrong dude. Can you post exactly what code you are using?

Dia_Byte Nov 12th, 2004 11:55 AM

no i did'nt do anything wrong !!

this is the source code of the program :


#include <iostream.h>

int main()
{

cout << "hello world\n";
return 0;
}

Pizentios Nov 12th, 2004 12:01 PM

hmmm, i have no idea what's going on then. Probally somthing to do with your compiller.

Ooble Nov 12th, 2004 1:19 PM

It's most probably the compiler - I'm afraid the only thing you can do is deal with it.

lostcauz Nov 12th, 2004 1:33 PM

With this code using win98:
:

#include <iostream>
using namespace std;

int main()
{
  cout << "hello world\n";
  return 0;
}

Compiled with MingW using
:

g++ -o big big.cpp
gave me an executable of 438kb
Using different switches to first convert to asm then compile
:

g++ -s big.cpp -o big2
gave me 206kb
I'm not sure if this can be reduced further other than switching to C.

kurifu Nov 12th, 2004 5:45 PM

Try giving it the switch -Os, that will likely help it a lot. I do not think that one header is causing that much bloat... it is also possible that you are generating debug information and having that inserted in there?

lostcauz Nov 12th, 2004 6:16 PM

On win98 with mingw gcc version 3.2 the -Os switch still gave me 438kb.
Using this code and saving as a C file.
:

#include <stdio.h>

int main()
{
  printf("hello world\n");
  return 0;
}

Compiled with:
:

gcc -o bigc bigc.c
gives 22kb

Compiled with:
:

gcc -s bigc.c -o bigc2
nets 11kb.

FWIW VC++6 gave me an executable of 221kb for the cpp code.

kurifu Nov 12th, 2004 11:20 PM

As an interesting note I decided to compile the exact same program and these are my results:

:

gcc -Os hello.c; ls -las a.out;
8 -rwxr-xr-x 1 kurifu users 6828 Nov 13 00:13 a.out


Only 6.8k in size... strange difference there...

:

gcc hello.c; ls -las a.out;
8 -rwxr-xr-x 1 kurifu users 6828 Nov 13 00:15 a.out


No change in results here....

:

bash-2.05b$ gcc -s hello.c
bash-2.05b$ ls -las a.out
4 -rwxr-xr-x 1 kurifu users 3180 Nov 13 00:16 a.out


Half the space saved here... but that is because the "-s" option strips uneeded and debugging information from the executable... I got the same results when I ran this:

:

bash-2.05b$ gcc -Os hello.c
bash-2.05b$ ls -las a.out
8 -rwxr-xr-x 1 kurifu users 6828 Nov 13 00:20 a.out
bash-2.05b$ strip a.out
bash-2.05b$ ls -las a.out
4 -rwxr-xr-x 1 kurifu users 3160 Nov 13 00:20 a.out


Now one thing we need to bear in mind is that I compiled this code to run on linux, which means that if you are using windows than we will have different executable formats, ELF in nature is smaller than windows' PE32 format.

Unstripped code will always vary in size depending on the amount of debugging information your compiler puts in there by default, and the format that it uses to record this information.. that may not be unusual sizes at all for what you are attempting to accomplish. Actually they seem very reasonable in my opinion.

Here is more information about my OS and compiler:

:

bash-2.05b$ uname -a; uptime; gcc -v;
Linux tsukasa 2.6.9-gentoo-r1 #1 Fri Nov 5 21:16:53 AST 2004 i686 Mobile Intel(R) Pentium(R) 4 - M CPU 2.40GHz GenuineIntel GNU/Linux
 00:23:42 up 1 day, 10:49, 3 users, load average: 0.06, 0.27, 0.25
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/specs
Configured with: /var/tmp/portage/gcc-3.3.4-r1/work/gcc-3.3.4/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.3 --includedir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3/man --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3/info --enable-shared --host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --with-system-zlib --enable-languages=c,c++,f77,objc --enable-threads=posix --enable-long-long --disable-checking --disable-libunwind-exceptions --enable-cstdio=stdio --enable-version-specific-runtime-libs --with-gxx-include-dir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/include/g++-v3 --with-local-prefix=/usr/local --enable-shared --enable-nls --without-included-gettext --disable-multilib --enable-__cxa_atexit --enable-clocale=generic
Thread model: posix
gcc version 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)



All times are GMT -5. The time now is 12:58 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC