Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including boost function.hpp, without using it, increases the size of my binary by 200k. Why?

I'm working on an embedded processor so binary size matters a lot. I am trying to avoid using the standard library. I'd like to use std::function, however. I extracted "function.hpp" from boost, and I'm trying to use that, but simply including function.hpp increases the size of my binary 200k, which makes it bigger than my processor can accept. If I include the standard library, it only increases my binary 60k. I can't figure it out, if I'm not using any of the templates yet, there shouldn't be any overhead. And even if I do, I can't imagine it's 200k worth of code. I'm using gcc 4.7, and I've disabled debugging info from what I can tell "-g0" and turned on optimizations "-O2".

Any help would be much appreciated.

like image 721
Kendrick Taylor Avatar asked Feb 05 '13 00:02

Kendrick Taylor


1 Answers

GCC includes some symbol information into the compiled binary even if you use -g0. In order to really get rid of all symbols one should use --strip-all command line option for the linker.

Also, since the size of the executable is important for you, consider -fdata-sections and -ffunction-sections for the compiler and --gc-sections for the linker.

like image 174
facetus Avatar answered Oct 16 '22 22:10

facetus