开发者

Using boost::serialization greatly increases binary size

I use rather complex d开发者_C百科ata 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*
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜