Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-19-2004, 06:15 AM   #1
LQ Newbie
Registered: Jul 2004
Location: Australia
Distribution: SUSE 9.0 (from a magazine)
Posts: 20

Rep: Reputation: 0
How do you make C++ programs smaller?

How come when I compile even a simple program that only prints a line on the screen it takes up 3 MB when an equivalent ASM program would be only 500 bytes or so? Even when I use the optimize option on the compiler it only reduces the file size a couple of kilobytes. Is there a way to reduce all that overhead in C++ and create ASM sized programs or what?
Would it work copying only the functions the program uses out of the include files?
Old 10-19-2004, 06:52 AM   #2
Registered: Jan 2004
Location: Munich
Distribution: SuSE 9.2, 10.2, 10.3, knoppix
Posts: 276

Rep: Reputation: 31
You're probably compiling it with debug information. Remove the -ggdb switch
in the makefile.
Old 10-19-2004, 09:25 AM   #3
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
Yeah, remove -g and -ggdb and pass -s when linking (it will strip the executable).
Old 10-19-2004, 02:32 PM   #4
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601

Rep: Reputation: 32
Also see the "strip" command.

Weird though -- shouldn't be *that* big... What's your linker command look like?
Old 11-03-2004, 05:33 AM   #5
LQ Newbie
Registered: Jul 2004
Location: Australia
Distribution: SUSE 9.0 (from a magazine)
Posts: 20

Original Poster
Rep: Reputation: 0
Yipee! I accidently solved the problem!
I reinstalled my distro (not because of this problem) and re-downloaded the gcc rpm's from the mirror, (I installed it last time using rpm's from and the openpkg tool). Somehow this solved it.
Old 11-05-2004, 12:32 AM   #6
Registered: Aug 2003
Location: San Francisco, California
Distribution: Slackware
Posts: 158

Rep: Reputation: 30
from what i remember, static binaries are around 3 megabytes when linked with libc.

try "ldd binary"

if static you will get:
"not a dynamic executable"

otherwise it will be something like:
Code: => /lib/ (0x4002e000) => /usr/lib/ (0x4007f000) => /lib/ (0x40136000) => /usr/lib/ (0x40158000) => /lib/ (0x40161000)
        /lib/ => /lib/ (0x40000000)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I make PDF documents smaller (In file size)? vdemuth Linux - Software 7 11-05-2011 10:39 AM
Why are linux programs smaller than win alternatives? awl Linux - Software 1 10-05-2005 08:00 PM
make mpg file size smaller secretlydead Linux - Software 2 02-14-2005 09:42 AM
how could i make my font size smaller in terminal Paxmaster Linux - Software 3 02-05-2005 09:43 PM
2.6.0-test9 kernel is 4mb, need to make smaller icyfire Linux - General 7 11-30-2003 04:14 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:04 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration