LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-14-2002, 07:10 AM   #1
sourceman
Member
 
Registered: Feb 2002
Posts: 48

Rep: Reputation: 15
Question Optimizing libs 'n executables.


The short version...

What is the best way to reduce the size of an executable and the libraries it relies on???????



The moaning version...

Here's a typical example of what I mean.

I write a little app in C.
Let's say I want the app to print a bunch of info to the screen, work out the MD5 of a file, and maybe zip a file or two.

Compile the source, cool, the executable is about 30k. Great.
But there's no way you can run it without...
libc.so
libz.so
libmd5.so

Which... brings the total size of the app up to something ridiculous.


I've tried using strip to make the libraries smaller...
Big deal, libc is still almost 1Mb in size.

I've tried statically including the libraries during compile time...
Sheeeeeesh... the executable becomes larger than 1Mb.

I've tried using UPX to shrink the exe a bit.
Yeah right... sometimes the app just refuses to work, and besides, it's still way too big.

I'd think my problems would go away by using an older kernel version and therefor a smaller libc.
But then I sit with.... yeesh... forget this one...
Why would I want an old kernel anyway.
Besides, libc is not that much smaller anyway.

To add to my pain, what if I want to set up a VESA video mode to at least make it look cool while it's doing what it should.

"Sorry sir, that will be another 300k off your limit"

And of course, there's this one...
I take my app to my buddies PC, but he has an older set of libraries than me, or he doesn't have libmd5.
Or how about, my buddy doesn't have Linux installed.
Which is mostly the case.

No problem, I'll make a quick boot disk with everything on.
Oh no, wait, I can't, 'cause it's kernel 2.4.?, and the libc file is just way too big. Sorry.



I can go on, but i've moaned enough now...

All of this is very good in one way.
It's a good system.
Why have each bit of code store it's own printf code when you can have one global printf in a library somewhere.
No waste of space and no needless repitition of code.


You may also be thinking, why would I want to run my app on any other box, linux or non linux, anyway?
Well, me, personally, it's what I do.



I moaned a lot now.
It's not frustration, i'm just asking...


If someone can teach me how to keep the size down...
I'll take back all my moaning with a smile.

I really hope there is a way, 'cause then I can move over to the latest kernel and set of libraries.
 
Old 02-14-2002, 09:58 AM   #2
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
You could use the following library which supports almost everything glibc does but is a lot smaller:
http://www.uclibc.org/uClibc.html

Another option is to remove all the functions in the libraries which you don't use for that application. Since you probably would only use just a small fraction of the libraries. Someone wrote a script for it I think it's included somewhere with debian. Just type the following string in google or whatever search engine you use:
mklibs.sh

Last edited by Mik; 02-14-2002 at 10:04 AM.
 
Old 02-15-2002, 01:42 AM   #3
sourceman
Member
 
Registered: Feb 2002
Posts: 48

Original Poster
Rep: Reputation: 15
Oh wow.

I compiled the (yew-see-lib-see) ((hehehehe)) libraries and smiled. Size does matter.

Yeah, now the fun starts.

Thanks for the help.

I'm gonna go play with all my new toys now.
Be back in a week or so.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Optimizing SUSE 9.3 ChuckB0612 Linux - Newbie 5 07-21-2005 01:40 PM
Optimizing Apache SiLiCoN Linux - Networking 2 06-15-2005 02:56 AM
optimizing apache alaios Linux - Networking 0 10-16-2004 12:08 PM
optimizing linux centr0 Linux - General 3 03-13-2003 04:12 PM
optimizing LINUX nautilus_1987 Linux - General 10 11-03-2002 11:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:56 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration