Ritardi Giuseppe
Ritardi Giuseppe

Reputation: 280

making a binary as little as possible

I have a program written in C and linked to a my static library (.a) in C too. How can I make this program as little as possible, without touch the code (I can recompile it etc)?

Upvotes: 2

Views: 228

Answers (3)

0xCAFEBABE
0xCAFEBABE

Reputation: 5666

There are a number of executable packers around that do what you want. First, strip any symbols like neuro suggested (if you have symbols compiled in), then use one of these executable packers: http://en.wikipedia.org/wiki/Executable_compression

Upvotes: 1

Lucas
Lucas

Reputation: 14129

If you are using gcc, the -Os flag will optimize for a small executable. I think gcc will try to link to shared libraries by default on most systems, but you might also want to look into that.

Upvotes: 0

neuro
neuro

Reputation: 15210

The first hing is to strip it from everything like debug symbols, etc.

On linux you can use in a terminal :

strip myexe

You will see the size greatly decrease ^^

I'm no windows guru, but if you use VS, use the release variant.

On every platform, do not use compiler flags that generate debug symbols. If you can use flags that optimize size.

And of course, if you use system libraries or common installed libraries, use dynamically linked libs (dll) or shared objects (so). The libs will not be included in your executable.

my2c

Upvotes: 1

Related Questions