简体   繁体   中英

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.

  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.
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*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM