LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 10-19-2004, 06:15 AM   #1
Qwirt
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
Marius2
Member
 
Registered: Jan 2004
Location: Munich
Distribution: SuSE 9.2, 10.2, 10.3, knoppix
Posts: 274

Rep: Reputation: 30
You're probably compiling it with debug information. Remove the -ggdb switch
in the makefile.
 
Old 10-19-2004, 09:25 AM   #3
Hivemind
Member
 
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
johnMG
Member
 
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601

Rep: Reputation: 31
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
Qwirt
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 gwdg.de mirror, (I installed it last time using rpm's from openpkg.org and the openpkg tool). Somehow this solved it.
 
Old 11-05-2004, 12:32 AM   #6
karlan
Member
 
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:
        libpthread.so.0 => /lib/libpthread.so.0 (0x4002e000)
        libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x4007f000)
        libm.so.6 => /lib/libm.so.6 (0x40136000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x40158000)
        libc.so.6 => /lib/libc.so.6 (0x40161000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
 
  


Reply


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


All times are GMT -5. The time now is 02:54 AM.

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