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

前端 未结 2 1428
鱼传尺愫
鱼传尺愫 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

    0 讨论(0)
  • 2020-12-05 10:33

    Use:

    g++ -u <SYMBOL_NAME> ...
    

    Note that -u is lowercase

    0 讨论(0)
提交回复
热议问题