Don't expose symbols from a used library in own static library

前端 未结 2 925
有刺的猬
有刺的猬 2020-12-25 08:21

I am writing a reusable static library for the iPhone, following the directions provided here.

I want to use minizip in my library internally, but don\'

相关标签:
2条回答
  • 2020-12-25 09:06

    Since static library is nothing more than a set of .o files (which are not linked yet, as you have mentioned), the only way to completely hide presence of minizip from the outside world is to somehow compile minizip and your library together as a single compilation unit and make minizip functions/variables static.

    You could have a look at how does SQLite do the "amalgamation" process which turns library source code into single .c file for further compilation: The SQLite Amalgamation.

    As a bonus you'll get better optimization (really recent GCC and Binutils are able to make link-time optimizations, but this functionality is not released yet).

    0 讨论(0)
  • 2020-12-25 09:12

    You could rename all exported symbol from minizip with objcopy.

    something like

    objcopy -redefine-sym=minizip.syms yourstaticlibray.a 
    

    and minizip.syms

    _unzOpen     _yourownprefix_unzOpen
    _unzOpen2    _yourownprefix_unzOpen2
    ...          ...
    

    No clash if an executable is linked with an other minizip.a and yourstaticlibray.a, and because you renamed all the symbol in yourstaticlibray.a your call inside yourstaticlibray.a to minizip will use the prefixed symbol, and not the unzOpen one.

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