Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i reduce compiled file sizes?

Status
Not open for further replies.

Flappy

Programmer
Jul 30, 2002
35
AU
Hi, I'm running Red Hat 8 and I'm programming in C and C++, but compiled file sizes seem to be a little bit big?

eg:

int main() {
int i=0;
}

when i compile this with: gcc -O2 test.c -o test
the file size is 9748kb - this seems a little bit large for one command - is there a way to reduce the size in anyway?

thanks.
 
Are you sure that that is the file size? Normally nothing programs are about 32K.

It is not a good idea to call your program test - there is a unix command called test.
 
when i do a ls -l thats the size that it reports, no small programs that i've ever compiled have ever come to 32k - usually the average small program compiles to around 10 or 11k

im just asking this question because i remember at a place i used to work the C programmer there compiled an advert software program that accessed databases etc and it was only 6k
 
It might be something to do with the default libraries. Yes: on embedded systems and older operating systems, the footprint can be quite small but on Unix and Windows, the loaders want as mass of information so the sizes are enormous but 9Mb is a bit big for a nothing program. I remember a full blown undersea cable monitoring system taht was only 4Mb! It may be something quirky like the OS just doesn't like the name test. Try a different name.
 
Yeah,

Sommit weird is going on here. I've got an ncurses app with 4 object files; 4.1k, 4.0k, 5.6k and 12k and the program when linked is only 37k!



William
Software Engineer
ICQ No. 56047340
 
Maybe you're compiling using static binding as opposed to using shared libraries. If you are compiling using static binding, all libraries are included in the executable, making it a larger file. Just a thought. Please correct me if am wrong.



Rene
 
No it's his ls... the size is 12k...
-l doesn't display units, so I checked -l -h and it comes to 12k.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top