c++ - Including unused code during compilation -


building application makefile have found excluding code class , using doesn't affected on size of built application.

// file // #include "someclass.h" ....... void myfunc() {      someclass _cl;      // _cl etc...      // _cl.somefunc();      ......... }   makefile ...... sources = ... someclass.cpp .... etc 

but if remove someclass.cpp makefile size of built application becomes less. why gcc doesn't optimize compiled code , don't exclude unused someclass final result?

you can configure through compile flags. on linux/gcc, unused symbols not eliminated binary - may of use when dl_open() binary. if want eliminate unused code, add -ffunction-sections , -fdata-sections compile options , --gc-sections linker options. compile options ensure every function placed in separate section (as opposed section per file), linker option throw unused sections away.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -