How to include all objects of an archive in a shared object?

前端 未结 1 1329
失恋的感觉
失恋的感觉 2020-11-28 09:19

When compiling our project, we create several archives (static libraries), say liby.a and libz.a that each contains an object file defining a funct

相关标签:
1条回答
  • 2020-11-28 10:04

    You could try (ld(2)):

       --whole-archive
           For each archive mentioned on the command line after the --whole-archive option, include every object file in the
           archive in the link, rather than searching the archive for the required object files.  This is normally used to turn
           an archive file into a shared library, forcing every object to be included in the resulting shared library.  This
           option may be used more than once.
    

    (gcc -Wl,--whole-archive)

    Plus, you should put -Wl,--no-whole-archive at the end of the library list. (as said by Dmitry Yudakov in the comment below)

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