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

前端 未结 11 2299
北荒
北荒 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:15

    I don't know if this will help with your current predicament as this is a recent feature, but you can specify the visibility of symbols in a global manner. Passing -fvisibility=hidden -fvisibility-inlines-hidden at compilation can help the linker to later get rid of unneeded symbols. If you're producing an executable (as opposed to a shared library) there's nothing more to do.

    More information (and a fine-grained approach for e.g. libraries) is available on the GCC wiki.

提交回复
热议问题