Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using boost::serialization greatly increases binary size

I use rather complex data structures (mostly using STL containers) in my app, and serialize them using Boost (v1.34).

Whenever I compile with debug symbols (gcc -g), the resulting executable gets huge - around 25 MB. Stripping all the debug symbols reduces the size to ~3 MB.

I tried to nail down the cause of the size increase, and it seems that serialization methods are the cause. Particularly, object files for modules that call serialization (code like "oarchive << myObject") are large, and commenting out the serialization part reduces the size significantly.

Is it possible to prevent generation of these symbols, or to strip them selectively?
Stripping all the symbols is not an option, since I need debug symbols for my own code.

like image 493
VladV Avatar asked May 19 '11 14:05

VladV


2 Answers

  1. Put your code with serialization calls to separate modules, compile them to large object files.
  2. Use strip --strip-debug on them to remove only this big debugging symbols (which you will definitely need later to debug crashes inside serialization library :)
  3. Profit! Link stripped wrappers and unstripped other modules together.
like image 120
blaze Avatar answered Nov 09 '22 00:11

blaze


strip -w -K '!*serialization*'

Easy, no need for compile time gymnastics. Here's the improvement this made to my binary:

# ls -lh EnrollGUI 
-rwxr-xr-x. 1 root root 17M Aug  8  2012 EnrollGUI*
# strip -w -K '!*serialization*' EnrollGUI
# ls -lh EnrollGUI 
-rwxr-xr-x. 1 root root 1.1M Aug  8  2012 EnrollGUI*
like image 2
John Kugelman Avatar answered Nov 09 '22 00:11

John Kugelman