How to remove unused C/C++ symbols with GCC and ld?

前端 未结 11 2312
北荒
北荒 2020-11-22 09:46

I need to optimize the size of my executable severely (ARM development) and I noticed that in my current build scheme (gcc + ld) unuse

11条回答
  •  迷失自我
    2020-11-22 10:32

    strip --strip-unneeded only operates on the symbol table of your executable. It doesn't actually remove any executable code.

    The standard libraries achieve the result you're after by splitting all of their functions into seperate object files, which are combined using ar. If you then link the resultant archive as a library (ie. give the option -l your_library to ld) then ld will only include the object files, and therefore the symbols, that are actually used.

    You may also find some of the responses to this similar question of use.

提交回复
热议问题