How to force gcc to link unreferenced, static C++ objects from a library

前端 未结 2 1441
鱼传尺愫
鱼传尺愫 2020-12-05 10:16

I\'m using a C++ library that can be built as either a shared or a static library. This library uses a factory technique, where static objects register themselves when the p

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 10:25

    You can use -Wl,--whole-archive -lyourlib , see the manpage for ld for more info.

    Any static libraries mentioned after -Wl,--whole-archive on the command line gets fully included, you can turn this off again too if you need to , as in e.g. -Wl,--whole-archive -lyourlib -Wl,--no-whole-archive -lotherlib

提交回复
热议问题